home *** CD-ROM | disk | FTP | other *** search
- {============================================================}
- { Unit Title - OpenGL Window }
- { }
- { Codemaster - John Hutchings }
- { Date - 10/6/98 }
- { DeBugged - }
- { }
- {============================================================}
-
- {$V+,X+,F+,B-}
- {$IFDEF MinSize} {$S-,L-,R-,Q-,D-} {$ENDIF}
-
- {===============================================================================
- Unit to encapsulate the OpenGL functional library into a standard
- DELPHI 3 VCL
-
- PURPOSE
-
- METHOD
-
- COMPILER DIRECTIVES
-
- DEBUG adds addition tests for valid data and type safe assigns
- MINSIZE limits debug and symbol info
-
- GLOBALS
-
- Classes
- Exceptions
- Variables
-
- Procedures
-
- EXCEPTIONS
-
- Drawing modes
- 2D GL mode draw to the screen using 2D commands via the GLCanvas og GL commands directly
- The viewport is set up to have the origin at the lower left of the screen with GL units representing pixels
- positive up and to the right.
- The X axis is to the right and the Y axis is up.
- Z is out of the screen but if used MUST be 1 or else data will be clipped
-
- This is used for foreground and background draws of Paper data
- eg grid, borders etc.
-
- 3D render mode
-
- Full 3D drawing via the GLCanvas ofr directly to the GL API. Standard GL conventions apply to the screen layout
- Refer to "OPENGL programming for Windows NT"
-
- Drawing process
-
- The control can be invalidated via the normal routes (Invalidate,Repaint etc)
-
- The process of drawing is
-
- 1. a 2D GL Render for background Paper stuff inc grid
- 2. the 3D Render of the data set
- 3. a Further 2D GL Render for Foregraound stuff
-
- 4. the normal GDI draw using the current glcanvas caled through the "Paint".
-
- NOTe the normal Canvas for this window should not be used if the GDI output
- is to go to the BitMap draws or printing outputs. You should always use the GLCanvas.
- The GLCanvas is a TCanvas but may be the window/bitmap/printer depending
- on the current operation.
-
- 5. a Head Up Display (HUD) render also is called if applicable to finally draw HUD data
- using the GDI and Canvas.
-
- Each should be implemented by overriding the internal call in descendant
- and/or using the Event handle provided.
-
- EVents available:
- OnBuildDisplay Called when a rebuild of the Display lists is needed
- can be triggered by a call to the BuildDisplayLists
- On2DForeGrnd Called when the 2d foreground drawing is taking place
- NOTE - the OpenGLCanvas set to 2D mode will be passed through
- - the window coordinates are the same as the window but 0,0 is bottom left
- On3DRender
- On2DBackGrnd
- OnPaint
- OnHUDUpdate
- OnSelect
-
- Most of the specialised events can be overriden by descendants of this
-
- ===============================================================================}
-
-
- unit glwin;
-
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, MmSystem, ExtCtrls,
- Controls, Forms, Dialogs, StdCtrls, ComCtrls, clipbrd,ActnList,
- OpenGL, opengl12, glAbsWin, glFuncs, glViewFr;
-
- Type
- // forward declarations
- TOpenGLCanvas = Class;
- TCustomOpenGLWindow = Class;
-
- // specialised event procedures
- TGLRenderEventNotify= procedure (Sender: TCustomOpenGLWindow;
- GLMode: GLRenderState;
- GL3DCanvas:TOpenGLCanvas) of object;
-
- TGLSelectEventNotify= procedure (Sender: TCustomOpenGLWindow;
- XPos,YPos:LongInt;
- WX,WY,WZ :Double;
- var RedrawNeeded:Boolean;
- var SelectState:GLSelectState) of object;
-
- tGDIUpdate = Procedure(sender:TCustomOpenGLWindow;aCanvas:TCanvas;SafeGDI:Boolean) of Object;
-
- tCustomViewSetUp = Procedure (Sender:TCustomOpenGLWindow) of Object;
-
- tAnimateNotify = Procedure (Sender:TCustomOpenGLWindow;ElapsedTime:DWord;
- Var DoRepaint:Boolean) of Object;
-
- //Main GL window Class
- TCustomOpenGLWindow = class(TAbstractOpenGL)
- private
- FCanvas : TCanvas;
- fGLCanvas : tOpenGLCanvas;
-
- { Private declarations }
- fOldMask : Pointer;
- // to handle possible Divide by zero errors
-
- fStartUpLoop, // Set to true after the first loop through the WMPaint;
- fLButtonDown, // LButton currently down
- fRButtonDown, //RButton ""
- fAnimationRunning, //Animation is on/off
- fViewAnimation, //VIEWER is in motion
- fClearedCurrentPos, //no need to redraw lastpos to current pos
- fSnapOn, // cursor snap is on
- fHUDon, // display HUD text / calls DrawHUDDisplay
- fFullFrameRate, // display at the fastest frame rate
- fViewportGridOn, //display the reference grid during background draw
- fViewportGridTextOn, // display the coord text at the left and bottom
- f3DCursorOn, // show cursor as the CAD XY lines
- fSimpleAxis, // show the simple XYZ axis
- fFirstMove, // first move for a move tool
- fAnimateViewPt, // true for a loop through the future view points
- fViewPtLoop // true for continous looping
-
- : Boolean;
-
- fViewPtIndex : LongInt; //current index of future viewpts
- fToolMode,
- fLastToolMode : GLToolMode;//current and last tool state
- fMoveMode,
- fLastMoveMode : GLMoveMode;//current and last movement state
- fRenderMode,
- fLastRenderMode : GLRenderState;
- fViewMode : GLViewMode;
- fSelectState : GLSelectState;
-
- fBackColor : GLBackground;
- fGLperPixel : GLFloat;
- //numbeer of GL units per screen pixel
-
- fViewClockStart,
- fViewElapsedTime : DWord;
- fClockStart,
- fElapsedTime : DWord;
- fShift : TShiftState;
- fCursorPlaneRec : tPlaneEq;
-
- // stores the data to manage a cursor plane
- // default is parrallel to the screen at z:=0.5;
- fXlStart,fXLend,
- fYLStart,fYLEnd,
- fZLStart,fZLEnd :tPoint;
- fxLineSet,fYLineSet,fZLineSet : Boolean;
- // Handle clearing the last 3D cursor;
-
- // Handles for main render events
- fOn2DbackgroundRender : TGLRenderEventNotify;
- // background 2D draw event handle
- f0nDrawRenderScene : TGLRenderEventNotify;
- // 3D render event handler
- fOn2DForeGroundRender : TGLRenderEventNotify;
- // 2D foreGround event handler
- fGDIPaint : tGDIUpdate;
- // GDI Paint event handler
- fOnHUDUpDate : tGDIUpdate;
- // HUD display update event handler
- fOnBuildDisplayLists : tGLRenderEventNotify ;
- //Build of display lists when required
- fOnSelectDown ,
- fOnSelectMove,
- fOnSelectUp : TGLSelectEventNotify;
- //Selection of objects required
- fOnCustomViewSetUp : tCustomViewSetUp;
- // handles a custom ModelView Matrix Setup.
- fOnAnimate : tAnimateNotify;
- //Handle Model animate actions
-
- (*
- fSelectBuffer : Pointer;
- fSelectBackSize,
- fSelectBackData : Longint;
- // manage the selection data
- *)
- procedure WMSize(var Message: TWMSize); message WM_SIZE;
-
- procedure GDIPaintWindow(DC: HDC);
- // hanlle the GDI painting
- procedure PaintWindow(DC: HDC); Override;
- // key to accessing the render stuff
-
- Procedure DoAnimate(Sender:tObject);
- //called by the animate timer
- Procedure DoViewerAnimate(Sender:tObject);
- //called by the viewer timer
- Procedure DrawMoveHint;
- // called during the GL draw
- procedure DrawMoveGuides(X,Y:LongInt);
- // use the canvas to draw the temporary lines for select/pan zoom etc
- procedure DrawToolGuides(X,Y:LongInt);
- //draw the temporary mouse lines
- Procedure DrawHUDDisplay;
- //draw the HUD screen data
- // calls to handle events and virtual methods
- Procedure GLRender2DForeGround;
- {Allow for the 2D drawing with in the buffer
- Is called after the 3D render}
- Procedure GLRender2DBackGround;
- {Allow for the 2D drawing with in the buffer
- Is called after the 3D render}
- Function GetWindowPos(aVal:LongInt):LongInt;
- //Use to return the Widow screen coordinate rather than the GL screen coordinate
- Procedure UpDateScreenZ(X,Y:Longint;aViewer:TViewFrame);
- //update the screen z from the current cursor plane found in fCursorplane
- Procedure CalcCursorPlane(aP1,aP2,aP3:tGLPoint;UseCustom:Boolean);
- // calc the required values for the cursor plane from P1,P2,P3);
- function GetPerspective: boolean;
- Function WX:GLDouble;
- Function WY:GLDouble;
- Function WZ:GLDouble;
- Function GetGLPerPixel:GLFloat;
- Function GetAnimation:Boolean;
- Function GetScale:Single;
- Function getXCubeSize:Double;
- Function getYCubeSize:Double;
- Function getZCubeSize:Double;
-
- { Procedure SetAngle(aAngle:Single);}
- Procedure SetXCubeSize(aVal:Double);
- Procedure SetYCubeSize(aVal:Double);
- Procedure SetZCubeSize(aVal:Double);
- Procedure SetPerspective(AState:Boolean);
- Procedure SetSimpleAxis(AState:Boolean);
- Procedure SetMode(aMode:GLMoveMode); Virtual;
- Procedure SetRenderMode(aRM:GLRenderState);
- Procedure SetBackColor(aColor:GLBackground);
- Procedure SetViewMode(aMode:GLViewMode);
- Procedure SetScale(aVal:Single);
- Procedure SetHUD(Val:Boolean );
- Procedure SetAnimation(aVal:Boolean);
- procedure SetViewportGridOn(aVal:Boolean);
- procedure SetViewportGridTextOn(aVal:Boolean);
- procedure SetCursor3D(aVal:Boolean);
- procedure SetStdDisplayList(aVal:Boolean);
-
- Procedure UpdateScreenPos;
- //will update all the LinkPoint screen positions
- Procedure ConvertScreenToWorld(aLinkPt:TLinkPoint;UseFar:Boolean);
- // Convert supplied linkPt to world If UseFar then will use back of model
- Procedure ConvertWorldToScreen(aLinkPt:TLinkPoint);
-
- Procedure Draw3DGDICursor(aGridType:GLGridType);
- // draw the CAD style cross hairs using the GDI canvas
- Procedure Draw3DCursor(aGridType:GLGridType);
- // draw CAD cursor with OpenGL
-
- Procedure Clear3DCursor;
- // clear up after the 3D cursor is drawn
-
- Procedure GetViewPortGrid(aGridType:GLGridType;aStep:LongInt);
- // set up the grid data
- Procedure DrawViewPortGrid(IncText:Boolean);
- // draw the viewport grid
- Procedure DrawSimpleAxis;
- //draw a simple X,Y,Z axis
- Procedure DrawSelectedPoints;
- //Draw the selected points according to current draw mode}
- {Create display list cursor}
- Procedure DrawBorder;
- // used to draw a border around the window, will show focus or not
- Function UpdateScreenCoordsLabel:String;
- // call to update a screen coord label if assigned
- Function UpdateExtraScreenCoordsLabel:String;
- // call to update a screen coord label if assigned
- Function SelectPolyClosed:Boolean;
- // test fselectlist for 'closed' poly select
- Procedure SetUpStdDisplayLists;
- //call to set up the standard display list (inc text)
- Procedure ShutDownStdDisplayLists;
- //call to shut down the standard display list (inc text
- //called when the stdDsiplaylist property is changed
- (*
- Procedure CancelSelectPoly;
- //cancel the select poly and clear the fselectlist*)
- protected
- { Protected declarations }
- fmodelMatrix : GLMatrixArrayd;
- fprojMatrix : GLMatrixArrayd;
- fviewport : GLViewPortArray;
- // Current matrices updated after each calc;
- fViewerTimer ,
- fAnimateTimer : tTimer;
- fDrawToOther, // set to true if cdrawing to a bitmap
- fStdDisplayList // true for using the std display lists
-
- :Boolean;
- {IDs from OpenGL Text}
- fGeneralLists : LongInt;
- //Display list index for flat text
- //display list index for general Display lists
- fDefaultTextID,
- //DisplayList index for 3D text
- fDefaultFlatTextID : LongInt;
-
- fOtherWidth,
- fOtherHeight : LongInt;
-
- fHome : tGLPoint;
-
- XDif,YDif,
- XStart,YStart : Longint; // mouse move differences
-
- fViewer : TViewFrame; //replace all next with TViewFrame
- fStartPos,
- fLastPos,
- fCurrentPos : tLinkPoint;
-
- fSelectPoints ,
- //List of selected tLinkPoints set by tools
- fMovePoints : tList;
- //set of points set by move modes
- fFutureViews,
- // list of possible future positions
- fPreviousViews : tList;
- // list of previous view records
- fGridPointsList : tList;
- // list of Grid Points projected and clipped to the screen
- // updated during moves etc
-
- fSnapPoint : tGLPoint;
- fLocationLabel,
- fExtraData : tStatusPanel;
-
- procedure CreateHandle; Override;
- procedure Paint; Virtual;
-
- Procedure GLRenderWindow(DoSwap:Boolean); Virtual;
- // Draw the window called by PaintWindow or the thread
- function GetPalette: HPALETTE; override;
-
- Procedure GLStartUp; Override;
- // Startn up the GLSession
- Procedure GLShutDown; Override;
- // Shut down a session
- procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer); override;
- procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
- procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer); override;
-
- procedure Click; Override;
- procedure DblClick; Override;
-
- Procedure GLSessionSetUp; Virtual;
- {Set up when GL session is started}
- Procedure Clearscreen; Virtual;
- //clear all the glbuffers
- Procedure UpdateScreenDisplayLists; Virtual;
-
- {This procedure builds all the standard display objects for the gl
- session}
- Procedure BuildGrids; Virtual;
- //set up the basic grid components
- Procedure BuildBitMapText(afontname:String;aSize:smallint);
- // build the basic bitmap font call if font changed using font name and size
- //font must be true type
- Procedure BuildOutLineFont(afontname:String);
- // 3D font
- //font must be true type
- Procedure CloseDisplayLists; Virtual;
- //closes display lists
-
- Procedure SetMoveMode(aMode:GLMoveMode); Virtual;
- Procedure SetToolMode(aMode:GLToolMode); Virtual;
- Procedure SetRefPoint(val:tGLPoint);
- // Set up the home point
-
- Procedure SetUpViewPort; Virtual;
- //Set up for the view port/s
- Procedure SetUpViewingFrustrum; Virtual;
- //set for Ortho or perspective
- Procedure SetUpViewingTransform; Virtual;
-
- Procedure DoMoveTidyUp; Override;
- // If pan zoom etc then tidy up the possible cursor draw
-
- // cals to be overridden in descendants
- Procedure DoGLRender2DForeGround; Virtual;
- {Render the stock platform or fixed background}
- Procedure Do3DRenderScene; Virtual;
- {Render the scene}
- Procedure DoGLRender2Dbackground; Virtual;
- {Background draw}
- Procedure DoHUDUpdate; Virtual;
-
- Procedure DoOnSelectDown(X,Y:Longint;Var ReDrawNeeded:Boolean);Virtual;
- // Handle the selection process
- Procedure DoSelectedMove(X,Y:Longint;Var ReDrawNeeded:Boolean); Virtual;
- // Used to manage the drag/stretch
- Procedure DoSelectMoveFinish(X,Y:Longint;Var ReDrawNeeded:Boolean); Virtual;
- // When a drag/stretch ids finished
-
- Procedure DoCustomViewSetUp; Virtual;
- // handle the setup of the ModelView Matrix for vmCustomview or special setups
-
- (* Procedure TextOut3D(anX,anY,anZ:glDouble;aSize:glFloat;aStr:String);*)
- // use the current base font to draw string
- Procedure StartViewerAnimation; Virtual;
- // start the animation timer
- Procedure StopViewerAnimation; Virtual;
- // stop the animation timer
- Procedure StartAnimation; Virtual;
- // start the animation timer
- Procedure StopAnimation; Virtual;
- // stop the animation timer
- Function ProjectOnScreen(aPt:tGLPoint;
- var ScreenPt:TPoint;
- var ZDepth:GLDouble):Boolean;
- Function ProjectLineOnScreen (var aPt1,aPt2 : tGLPoint):Boolean;
- // project the given 3D line ont the screen returning the modified tGLPoint
- // Values. Return true if sucessful
-
- Function GetFromScreen(var aPt:tGLPoint;
- ScreenPt:TPoint;
- ZDepth:GLDouble):Boolean;
-
- Procedure GetFrontBackPoints(const XVal,YVal:Longint;ZVal,ticht:Double;
- var Point,BackPt,FrontPt,ticPt:tGLPoint);
- // get the data to be able to draw line from front to back
- public
- { Public declarations }
- constructor Create(AOwner: TComponent); Override;
- destructor Destroy; override;
-
-
- procedure SetFocus; override;
-
- //gl Function wrappers
- Procedure CallList(aVal:GLuint);
- //handles the glCalllist after testing the value
-
- Procedure ReSetView(ReSetRange:Boolean); Virtual;
- // reset the current view mode back to the start point
- Procedure DoPan; Virtual;
- //Set up the current view for a Pan
- Procedure DoMove;
- Procedure DoWalk;
- Procedure DoFly;
- Procedure DoRotate;
- Procedure DoSlide;
- Procedure DoMeasure(X,Y:LongInt);
- Procedure DoZoom;
- Procedure DoTwist;
- Procedure DoScreenZ;
- Procedure DoLookAt;
- Procedure DoLookAtPt;
- Procedure DoZoomIn; Virtual;
- //set up the current view for a standard view in
- Procedure DoZoomOut; Virtual;
- //set up the current view to a zoom out
- Procedure ZoomAll; Virtual;
- //zoom to the current space;
-
- Function GetGLVendor:pchar;
- Function GetGLRenderer:pchar;
- Function GetGLVersion:pchar;
- Function GetGLExtensions:pchar;
-
- Procedure BuildDisplayLists; Virtual;
- //call when screen size changes
-
- Procedure MoveViewByDelta(DeltaX,DeltaY,DeltaZ:GLDouble);
- //will move fPosition and Lookat by delta
-
- { Public declarations }
- {Set the XRot andYRot values}
- Procedure ClearSelectList;
- // clear the selected points list
- Procedure ClearMoveList;
- //clear the move points list
- Function IsPointOutSideSelectPoly(X,Y:LongInt):Boolean;
- //return if the screen X,Y is inside the selection polygon Return false if zero set
- Function IsPointInsideSelectPoly(X,Y:LongInt):Boolean;
- //return if the screen X,Y is outside the selection polygon
- Procedure GetMeasurementData(var aMeasRec:tMeasureRecord);
- //Used to fill record with current move point data
- Procedure SnapToPoint(aX,aY,aZ:Double;aHint:String);
- // Move the cursor to this point and set the screenZ to the correct value
- Procedure CopyCurrentView;
- // make a copy of the curent viewing position
- Procedure RestoreLastView;
- // restore the last viewing position
-
- Procedure ShowGLHint(Var aHintStr:String; Var CanShow:Boolean; Var HintInfo:tHintInfo);
- // call to handle any hint showing stuff
- // this does not belong here
- Procedure getBitMapImage(aBP:tBitMap);
- //return bitmap filled with current view
- Function getMetaFileImage(aMF:tMetaFile;UseMFHeight:Integer;XScale,YScale:Double):Boolean;
- //return the current view as a Metsfile
- Procedure getFittedBitMapImage(aBP:tBitMap);
- //return a specially composed bitmap filled with current view
- Function getScaledMetaFileImage(PixSizeX,PixSizeY:Integer; //Pixel size of window
- PixResX,PixResY:Single; //scale in Pixel/mm
- aPrintScale:Double):tMetaFile;//scale value -1=not to scale
- //draw the image to the Metafile. Will fail if in perspective view.
- Function GetSizedBitMapImage(aBP:tBitMap):Boolean;
- //return a bitmap sized to the supplied bitmap of current view
- Procedure CopyToClipBoard;
- //copy the current view to the clipboard as a bitmap and metafile
- Procedure getBirdsEyeView(aBP:tBitMap;aSize:LongInt);
- //return bitmap filled with bitmap centred on mouse pos and size
-
- property Canvas :TCanvas read fCanvas ;
- // canvas for GDI Painting
- property GLCanvas :tOpenGLCanvas read fGLCanvas;
- // Canvas for OpenGL work
- Property GLVendor :pchar Read GetGLVendor;
- Property GLRenderer:pchar Read GetGLRenderer;
- Property GLVersion :pchar Read GetGLVersion;
- Property GLExtensions:pchar Read GetGLExtensions;
-
- Property Coords :tStatusPanel Read fLocationLabel Write fLocationLabel;
- Property ExtraData :tStatusPanel Read fExtraData Write fExtraData;
- Property DisplayList:LongInt read fGeneralLists;
- Property GLPalette :HPalette Read fGLPalette;
- Property MovePoints :TList Read fMovePoints;
- Property SelectList :TList Read fSelectPoints;
- Property Viewer :TViewFrame Read fViewer;
- property UnitsPerPixel:GLFloat Read GetGLPerPixel ;
-
- property MouseX:GLDouble Read WX;
- property MouseY:GLDouble Read WY;
- property MouseZ:GLDouble Read WZ;
-
-
- {New properties}
- Property Animate :Boolean Read GetAnimation Write setAnimation;
- Property BackGround :GLBackground Read fBackColor write SetBackColor;
-
- Property BoxSizeX :Double read getXCubeSize Write SetXCubeSize;
- Property BoxSizeY :Double read getYCubeSize Write SetYCubeSize;
- Property BoxSizeZ :Double read getZCubeSize Write SetZCubeSize;
- Property Cursor3D :Boolean Read f3DCursorOn Write SetCursor3D;
-
- Property Grid :Boolean Read fViewportGridOn write SetViewportGridOn;
- Property GridText :Boolean Read fViewportGridTextOn write SetViewportGridTextOn;
- Property HUD :Boolean Read fHUDon Write SetHUD;
- Property MaxFrmRate :Boolean Read fFullFrameRate Write fFullFrameRate;
- Property MoveMode :GLMoveMode Read fMoveMode write SetMode;
- Property Perspective:Boolean read GetPerspective write SetPerspective;
- Property RefPoint :tGLPoint read fHome Write SetRefPoint;
- Property SimpleAxis :Boolean read fSimpleAxis write SetSimpleAxis;
- Property Scale :Single Read GetScale Write SetScale;
- Property StdDisplayList :Boolean Read fStdDisplayList Write SetStdDisplayList;
- Property ToolMode :GLToolMode Read fToolMode write setToolMode;
- Property ViewMode :GLViewMode Read fViewMode Write SetViewMode;
- Property RenderState:GLRenderState read fRenderMode Write SetRenderMode;
-
- {GL Specific RENDERING EVENTS}
-
- Property OnBuildDisplayList:TGLRenderEventNotify read fOnBuildDisplayLists write fOnBuildDisplayLists;
- Property On2DForeGrnd:TGLRenderEventNotify read fOn2DForeGroundRender write fOn2DForeGroundRender;
- Property On3DRender :TGLRenderEventNotify read f0nDrawRenderScene write f0nDrawRenderScene;
- Property On2DBackGrnd:TGLRenderEventNotify read fOn2DbackgroundRender write fOn2DbackgroundRender;
- Property OnPaint :tGDIUpdate read fGDIPaint write fGDIPaint;
- Property OnHUDUpdate :tGDIUpdate read fOnHUDUpDate write fOnHUDUpDate;
- Property OnSelectDown :TGLSelectEventNotify Read fOnSelectDown Write fOnSelectDown;
- Property OnSelectMove :TGLSelectEventNotify Read fOnSelectMove Write fOnSelectMove;
- Property OnSelectUp :TGLSelectEventNotify Read fOnSelectUp Write fOnSelectUp;
- Property OnCustomView :tCustomViewSetUp Read fOnCustomViewSetUp Write fOnCustomViewSetUp;
- Property OnAnimate :tAnimateNotify Read fOnAnimate Write fOnAnimate;
-
- end;
-
- TOpenGLCanvas = class(Tpersistent)
- private
- fGLWin : TCustomOpenGLWindow;
- f3DMode : Boolean;
- fColor : glColorVal;
- fCurrentPoint: tGLPoint;
- fPointSize : glFloat;
- fPointMode : glPointMode;
- fLineWidth : GLFloat;
- fStipple : gluShort;
- {fPattern : glint;}
-
- Protected
- Procedure SetLineWidth(aWidth:glFloat);
- Procedure SetLineStyle(aStyle:gluShort);
-
- Public
- constructor Create(AOwner: TComponent);
- destructor Destroy; override;
-
- Procedure DrawPoint(aPt:tGLPoint);
- Procedure MoveTo(aPt:tGLPoint);
- Procedure LineTo(aPt:tGLPoint);
- Procedure DrawLine(aStart,aEnd:tGLPoint);
- Procedure DrawTriangle(P1,P2,P3:tGLPoint;C1,C2,C3:glColorVal);
- Procedure DrawQuad(P1,P2,P3,P4:tGLPoint;C1,C2,C3,C4:glColorVal);
- Procedure DrawRectangle(P1,P2:tGLPoint);
- Procedure TextOut2D(loc:tGLPoint;aSize:glFloat;aStr:String);
- Procedure TextOut3D(loc:tGLPoint;aSize:glFloat;aStr:String);
- (* Procedur DrawPolyLine(aPtCol:tCollection);*)
- Procedure DrawAxis(loc:tGLPoint;aSize:glFloat;aMode:GLRenderState);
- Procedure CircleXY(loc:tGLPoint;XRadius,YRadius:glFloat);
- Procedure CircleYZ(loc:tGLPoint;YRadius,ZRadius:glFloat);
- Procedure CircleXZ(loc:tGLPoint;XRadius,ZRadius:glFloat);
- Procedure DrawSelectHandle(aSize:Double);
- // Selection handle at present position
- Procedure DrawLockedSelectHandle(aSize:Double);
- // draw locked selection handle
-
- property Color:GLColorVal Read fColor Write fColor;
- Property PointMode:glPointMode Read fPointMode write fPointMode;
- Property PointSize:glFloat Read fPointSize Write fPointSize;
- Property LineWidth:GLFloat Read fLineWidth Write setLineWidth;
- Property LineStyle:gluShort read fStipple write setLineStyle;
-
- end;
-
- { TCustomOpenGLWindowActionLink }
-
- TCustomOpenGLWindowActionLink = class(TControlActionLink)
- protected
- FClient: TCustomOpenGLWindow;
- procedure AssignClient(AClient: TObject); override;
- function IsHelpContextLinked: Boolean; override;
- procedure SetHelpContext(Value: THelpContext); override;
- end;
-
- TCustomOpenGLWindowActionLinkClass = class of TCustomOpenGLWindowActionLink;
-
- {procedure Register;}
-
- (*************************************************************)
- implementation
- (*************************************************************)
-
- constructor TCustomOpenGLWindow.Create(AOwner: TComponent);
- Begin
- Inherited Create(aOwner);
- FCanvas := TControlCanvas.Create;
- TControlCanvas(FCanvas).Control := Self;
-
- fGrabFocus:=True;
- fViewer:= TViewFrame.Create;
- fAnimationRunning := False;
- fViewAnimation :=False;
- fBackColor :=glWhiteBkgd;
-
- SetGLPointVal(fHome,0,0,0);
-
- fViewElapsedTime:=0;
-
- {fSelectMode:=snone;}
- fToolMode := tlNone;
- fLastToolMode := tlNone;
- fMoveMode := mmNone;
- fLastMoveMode := mmNone;
-
- fStartPos := tLinkPoint.Create;
- fLastPos := tLinkPoint.Create;
- fCurrentPos := tLinkPoint.Create;
- fSelectPoints := tList.Create;
- fMovePoints := tList.Create;
- fFutureViews := tList.Create;
- fPreviousViews:= tList.Create;
- fGridPointsList:= tList.create;
-
-
- fViewMode:= vmLookDown;
- // set to identity for start
- fmodelMatrix[1]:=1;
- fmodelMatrix[6]:=1;
- fmodelMatrix[11]:=1;
- fmodelMatrix[16]:=1;
- fprojMatrix[1]:=1;
- fprojMatrix[6]:=1;
- fprojMatrix[11]:=1;
- fprojMatrix[16]:=1;
- // setup nominal values
- fviewport[1]:=0;
- fviewport[2]:=0;
- fviewport[3]:=600;
- fviewport[4]:=800;
-
- fDrawToOther:=False;
- With fCursorPlaneRec do
- Begin
- A:=0;B:=0;C:=0;D:=0;IsValid:=False;
- end;
- fStdDisplayList:=False;
- end;
- (******* ******************************************************)
- Procedure TCustomOpenGLWindow.GLStartUp;
- // Startn up the GLSession
- Begin
- Inherited GLStartUp;
- // set up local list stuff
- SetUpStdDisplayLists;
- // set the base for GL lists
- GLSessionSetUp;
-
- glListBase(0);
-
- //dispose of the temporary value from the ancestor
- fGLCanvas := TOpenGLCanvas.Create(self);
-
- fAnimateTimer := tTimer.Create(Self);
- fViewerTimer := tTimer.Create(Self);
- With fAnimateTimer do
- Begin
- Enabled:=False;
- Interval:= 5;
- OnTimer:=DoAnimate;
- end;
-
- With fViewerTimer do
- Begin
- Enabled:=False;
- Interval:= 5;
- OnTimer:=DoViewerAnimate;
- end;
- // turn GL session back on after thread setup
- {Set up the initial Viewing Transforms}
- // check for GLErrors
- GetError;
- fGDIGeneric:= (GetGLVendor='Microsoft Corporation') and
- (GetGLRenderer='GDI Generic');
-
- end;
- (******* ******************************************************)
- Procedure TCustomOpenGLWindow.SetUpStdDisplayLists;
- Begin
- If not fStdDisplayList then exit;
- If not assigned(fShareGL) then
- Begin
- fGeneralLists:=glGenLists(glGeneralListSize);
- // bitmap text stuff
- fDefaultFlatTextID:=glGenLists(256);
- // 3D text ARIAL font
- fDefaultTextID:=glGenLists(256);
- end else
- Begin
- If (fShareGL is TCustomOpenGLWindow)then
- Begin
- fGeneralLists:=TCustomOpenGLWindow(fShareGL).fGeneralLists ;
- fDefaultTextID:=TCustomOpenGLWindow(fShareGL).fDefaultTextID;
- fDefaultFlatTextID:=TCustomOpenGLWindow(fShareGL).fDefaultFlatTextID;
- end;
- end;
- end;
- (******* ******************************************************)
- Procedure TCustomOpenGLWindow.ShutDownStdDisplayLists;
- Begin
- If not assigned(fShareGL) then
- Begin
- glDeleteLists(fGeneralLists,glGeneralListSize);
- glDeleteLists(fDefaultFlatTextID,256);
- glDeleteLists(fDefaultTextID,256);
- end;
- fGeneralLists:=0;
- fDefaultTextID:=0;
- fDefaultFlatTextID:=0;
- end;
- (******* ******************************************************)
- Procedure TCustomOpenGLWindow.CallList(aVal:GLuint);
- Begin
- If not fStdDisplayList then exit;
- If glIsList(aVal) then
- glcallList(aVal);
- end;
- (******* ******************************************************)
- Procedure TCustomOpenGLWindow.GLShutDown;
- // Shut down a session
- Begin
- ShutDownStdDisplayLists;
- Inherited GLShutDown;
- end;
- (******* ******************************************************)
- destructor TCustomOpenGLWindow.Destroy;
- Var i:LongInt;
- Begin
- {Ensure all GL stuff is freed}
- fGLCanvas.Free;
- If assigned(fCanvas) then fCanvas.Free;
- {If Assigned(fAnimateThread) then fAnimateThread.Free;}
- If Assigned(fAnimateTimer) then fAnimateTimer.Free;
- If Assigned(fViewerTimer) then fViewerTimer.Free;
-
- fStartPos.Free;
- fLastPos.Free;
- fCurrentPos.Free;
-
- For i:=0 to fSelectPoints.count-1 do
- tLinkPoint(fSelectPoints.Items[i]).Free;
- fSelectPoints.Clear;
- fSelectPoints.Free;
-
- For i:=0 to fMovePoints.count-1 do
- tLinkPoint(fMovePoints.Items[i]).Free;
- fMovePoints.Clear;
- fMovePoints.Free;
-
- For i:=0 to fGridPointsList.count-1 do
- FreeMem(fGridPointsList.Items[i],SizeOf(tGLPoint));
- fGridPointsList.Clear;
- fGridPointsList.Free;
-
- fViewer.Free;
-
- // tidy up the animate view positions
- For i:=0 to fFutureViews.Count-1 do
- TViewFrame(fFutureViews.Items[i]).Free;
- fFutureViews.Clear;
- fFutureViews.Free;
-
- // tidy up previous views
- For i:=0 to fPreviousViews.Count-1 do
- TViewFrame(fPreviousViews.Items[i]).Free;
- fPreviousViews.Clear;
- fPreviousViews.Free;
- Inherited Destroy;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.WMSize(var Message: TWMSize);
- Var I:LongInt;
- Begin
- Inherited;
- //valid OpenGL session
- if fHRC<>0 then
- Begin
- glLock;
- UpdateScreenDisplayLists;
-
- SetUpViewPort;
- SetUpViewingFrustrum;
-
- DoMoveTidyUp;
- // set the height field for all the link points
- fStartPos.SetHeight(height);
- fLastPos.SetHeight(height);
- fCurrentPos.SetHeight(height);
-
- For i:=0 to fSelectPoints.Count-1 do
- tLinkPoint(fSelectPoints.Items[I]).SetHeight(height);
- For i:=0 to fMovePoints.Count-1 do
- tLinkPoint(fMovePoints.Items[I]).SetHeight(height);
- UpdateScreenPos;
- glUnlock;
- end;
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.CreateHandle;
- Begin
- Inherited;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.SetFocus;
- begin
- fFirstMove:=True;
- fClearedCurrentPos:=True;
- UpdateScreenPos;
- Inherited;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.SetUpViewPort;
- {Set up for the view port/s}
- Begin
- if fHRC=0 then exit;
- EnableGL;
- //allow for a border around the window
- If not fDrawToOther then
- glViewport(0,0,width,height) else
- glViewport(0,0,fOtherWidth,fOtherHeight);
- glGetIntegerv(GL_VIEWPORT,pGLInt(@fViewPort));
- // viewport matrix
- // check for GLErrors
- GetError;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.SetUpViewingFrustrum;
- Var h,w:GLint;
- aspect:GLDouble;
- Dist:Double;
- Begin
- if fHRC=0 then exit;
- EnableGL;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity;
- If not fDrawToOther then
- Begin
- If Height=0 then h:=1 else h:=height-2*fBorderWidth;
- If Width=0 then w:=1 else w:=width- 2*fBorderWidth;
- end else
- Begin
- If fOtherHeight=0 then h:=1 else h:=fOtherHeight;
- If fOtherWidth=0 then w:=1 else w:=fOtherWidth;
- end;
-
- with fViewer do
- begin
- Dist:=Distance*20;
- aspect:=w/h;
- If Perspective then
- Begin
- gluperspective(ViewAngle,aspect,10,dist);
- If w>h then fGLperPixel:= Range/h else fGLperPixel:=Range/Width;
- end else
- //manage the perspective case or the Ortho case
- If w>h then
- Begin
- glOrtho(-Range*aspect,Range*aspect,-Range,Range,10,Dist);
- fGLperPixel:= Range/h;
- end else
- Begin
- glOrtho(-Range,Range,-Range/aspect,Range/aspect,10,Dist);
- fGLperPixel:=Range/width;
- end;
- glGetDoublev(GL_PROJECTION_MATRIX,pGLDouble(@fprojMatrix));
- // projection matrix
- glMatrixMode(GL_MODELVIEW);
- end;
- // check for GLErrors
- GetError;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.SetUpViewingTransform;
- Begin
- if fHRC=0 then exit;
- EnableGL;
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity;
-
- If fViewMode<>vmCustom then
- with fViewer do
- gluLookAt(Position.X, Position.Y, Position.Z,
- LookAt.X, LookAt.Y, LookAt.Z,
- UpVector.X, UpVector.Y, UpVector.Z)
-
- else
- DoCustomViewSetUp;
-
- If fViewer.Scale<>1 then
- // Handle scaling 3.281=feet
- with fViewer do
- glScalef(Scale,Scale,Scale);
-
- // Calc the ModelView Matrix
- glGetDoublev(GL_MODELVIEW_MATRIX,pGLDouble(@fModelMatrix));
- // get the matrix
- UpdateScreenPos;
- // update all screen positions after a screen setup
- fValidBuffer:=False;
- // check for GLErrors
- GetError;
-
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.ReSetView(ReSetRange:Boolean);
- // reset the current view mode back to the start point
- Var aScrnPt:TPoint;
- TempDist,tempZ:Double;
- P1,P2,P3:tGLPoint;
- Begin
- if fHRC=0 then exit;
- with fViewer do
- begin
- LookAt:= fHome;
- UpVector:= z_vector;
-
- Case fViewMode of
- vmLookDown:Begin
- TempDist:=2*ZRadius;
- SetViewer3d(fHome.X,fHome.Y,fHome.Z+TempDist);
- UpVector:= y_vector;
- end;
- vmLookUp:Begin
- TempDist:=2*ZRadius;
- SetViewer3d(fHome.X,fHome.Y,fHome.Z-TempDist);
- UpVector:= y_vector;
- end;
- vmLookWest: Begin
- TempDist:=2*XRadius;
- SetViewer3d(fHome.X-TempDist,fHome.Y,fHome.Z);
- end;
- vmLookEast:Begin
- TempDist:=2*XRadius;
- SetViewer3d(fHome.X+TempDist,fHome.Y,fHome.Z);
- end;
- vwLookNorth: Begin
- TempDist:=2*YRadius;
- SetViewer3d(fHome.X,fHome.Y-TempDist,fHome.Z);
- end;
- vmLookSouth:Begin
- TempDist:=2*YRadius;
- SetViewer3d(fHome.X,fHome.Y+TempDist,fHome.Z);
- end;
- vmCustom:Begin
- TempDist:=2*YRadius;
- SetViewer3d(fHome.X,fHome.Y-TempDist,fHome.Z);
- end;
- else begin
- TempDist:=2*ZRadius;
- SetViewer3d(fHome.X,fHome.Y,fHome.Z-TempDist);
- end;
- end; {case}
- if ReSetRange then
- begin
- Case fViewMode of
- vmLookDown,vmLookUp :If XRadius>YRadius then TempDist:=Yradius else TempDist:=Xradius;
- vmLookWest,vmLookEast :If YRadius>ZRadius then TempDist:=Zradius else TempDist:=Yradius;
- vwLookNorth,vmLookSouth:If XRadius>ZRadius then TempDist:=Zradius else TempDist:=Xradius;
- vmCustom: TempDist:=DefaultSize;
- else TempDist:=DefaultSize;
- end;
- end;
- setRange(TempDist,True);
- end; //end with viewer
-
- SetUpViewPort;
- SetUpViewingFrustrum;
- SetUpViewingTransform;
-
- fValidBuffer:=False;
-
- //Set screenZ value by projecting fHome onto the screen
- If not ProjectOnScreen(fHome,aScrnPt,TempZ) then
- TempZ:=0.5;
- viewer.screenZ:=TempZ;
- CalcCursorPlane(P1,P2,P3,False);
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.GDIPaintWindow(DC: HDC);
- begin
- FCanvas.Lock;
- try
- FCanvas.Handle := DC;
- try
- TControlCanvas(FCanvas).UpdateTextFlags;
- Paint;
- If fGDIGeneric then DrawHUDDisplay;
- // draw the HUD display if required
- //Allow for the GUI paint after swap buffers
- DrawMoveHint;
- // draw the on screen data
- // MUST use only canvas draw;
- finally
- FCanvas.Handle := 0;
- end;
- finally
- FCanvas.Unlock;
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoMoveTidyUp;
- // If pan zoom etc then tidy up the possible cursor draw
- Begin
- fClearedCurrentPos:=True;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoPan;
- //Set up the current view for a Pan
- var DX,DY,DZ:Double;
- Begin
- DoMoveTidyUp;
- DX:=fStartPos.X-flastPos.X;
- DY:=fStartPos.Y-flastPos.Y;
- DZ:=fStartPos.Z-flastPos.Z;
- if (abs(Dx)<MoveTolerance) and
- (abs(Dy)<MoveTolerance) and
- (abs(DZ)<MoveTolerance) then exit;
- MoveViewByDelta(DX,DY,DZ);
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoMove;
- Begin
- DoMoveTidyUp;
- fViewer.SetViewer3d(flastPos.X,flastPos.Y,flastPos.Z);
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoLookAtPt;
- Begin
- DoMoveTidyUp;
- fViewer.SetLookAt3d(flastPos.X,flastPos.Y,flastPos.Z);
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoWalk;
- Begin
- DoMoveTidyUp;
- fViewer.AdvanceToLookAt(-2*YDif/RotSensitivity);
- fViewer.RotateAboutViewer(XDif/(RotSensitivity*2),0);
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoFly;
- Begin
- DoMoveTidyUp;
- If (ssShift in fShift) then
- fViewer.FlyBy(-fly_speed,XDif/RotSensitivity,YDif/RotSensitivity)
- else
- fViewer.FlyBy(fly_speed,XDif/RotSensitivity,YDif/RotSensitivity);
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoRotate ;
- Begin
- DoMoveTidyUp;
- fViewer.RotateAboutLookAt(XDif/RotSensitivity,YDif/RotSensitivity);
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoSlide;
- var
- Dx,Dy,DZ:GLDouble;
-
- Begin
- DoMoveTidyUp;
-
- fStartPos.SetWinScreenPt(XStart,YStart,height,fViewer.ScreenZ);
- ConvertScreenToWorld(fStartPos,False);
-
- Dx:=fCurrentPos.X-fStartPos.X;
- DY:=fCurrentPos.Y-fStartPos.Y;
- DZ:=fCurrentPos.Z-fStartPos.Z;
- MoveViewByDelta(-DX/20,-DY/20,-DZ/20);
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoMeasure(X,Y:LongInt);
- Begin
- DoMoveTidyUp;
- fMovePoints.Add(fCurrentPos.Duplicate);
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.DoZoom;
- var
- Cx,Cy,Cz:GLDouble;
- Dx,Dy,DZ:GLDouble;
- SCX,SCY:LongInt;
- NewRange:Double;
- P1,P2,P3:tGLPoint;
-
- Function getMidPoint(D1,D2:Double):Double;
- Begin
- If D1=D2 then
- Begin
- Result:=D1;
- exit;
- end;
- If D1>D2 then
- Result:=((D1-D2)/2)+D2
- else
- Result:=((D2-D1)/2)+D1;
- end;
- Begin
- {CopyCurrentView;}
- If fViewer.perspective then UpdateScreenPos;
- DoMoveTidyUp;
-
- Cx:=GetMidPoint(fCurrentPos.X,fStartPos.X);
- Cy:=GetMidPoint(fCurrentPos.y,fStartPos.y);
- Cz:=GetMidPoint(fCurrentPos.z,fStartPos.z);
-
- Dx:=Cx-fViewer.LookAt.X;
- Dy:=Cy-fViewer.LookAt.y;
- Dz:=Cz-fViewer.LookAt.z;
- fViewer.SetLookAt3d(cx,cy,cz);
-
- cx:=fViewer.position.x+DX;
- cy:=fViewer.position.y+Dy;
- cz:=fViewer.position.z+Dz;
- fViewer.setviewer3d(cx,cy,cz);
-
- If not fViewer.Perspective then
- Begin
- SCX:=abs(fCurrentPos.SX-fStartPos.SX);
- SCy:=abs(fCurrentPos.Sy-fStartPos.Sy);
- If SCX>=SCY then
- NewRange:=SCX*fGLperPixel else
- NewRange:=SCY*fGLperPixel;
- fViewer.SetRange(NewRange,True);
- end;
- SetUpViewingFrustrum;
- CalcCursorPlane(P1,P2,P3,False);
-
- UpdateScreenPos;
-
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoTwist;
- Begin
- DoMoveTidyUp;
- fViewer.RotateUpVector(XDif/RotSensitivity);
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoScreenZ;
- Begin
- DoMoveTidyUp;
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoLookAt;
- Begin
- CopyCurrentView;
- DoMoveTidyUp;
- fViewer.RotateAboutViewer(-XDif/RotSensitivity,-YDif/RotSensitivity);
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoZoomIn;
- //set up the current view for a standard view in
- Begin
- CopyCurrentView;
- DoMoveTidyUp;
- fViewer.SetRange(fViewer.Range*0.8,True);
- SetUpViewingFrustrum;
- UpDateScreenPos;
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoZoomOut;
- //set up the current view to a zoom out
- Begin
- CopyCurrentView;
- DoMoveTidyUp;
- fViewer.SetRange(fViewer.Range/0.8,True);
- SetUpViewingFrustrum;
- UpDateScreenPos;
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.ZoomAll;
- //zoom to the current space;
- Begin
- CopyCurrentView;
- DoMoveTidyUp;
- ReSetView(True);
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.MoveViewByDelta(DeltaX,DeltaY,DeltaZ:GLDouble);
- //will move fPosition and Lookat by delta
- Begin
- DoMoveTidyUp;
- fViewer.MoveFrame(DeltaX,DeltaY,DeltaZ);
- SetUpViewingTransform;
- Repaint;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.Paint;
- {GUI paint which will be called after the Render function}
- Begin
- If Assigned(fGDIPaint) then fGDIPaint(Self,fCanvas,fGDIGeneric);
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.GetWindowPos(aVal:LongInt):LongInt;
- //Use to return the Widow screen coordinate rather than the GL screen coordinate
- Begin
- Result:=height-aVal ;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.DrawMoveGuides(X,Y:LongInt);
- Var
- OldMode:TPenMode;
- oldStyle:TPenStyle;
- oldColor:TColor;
- oldBStyle:tBrushStyle;
- X1,X2,Y1,Y2:LongInt;
- Begin
- iF fmovemode=mmnone then
- Begin
- exit;
- end;
- If fGDIGeneric then
- Begin
- With fCanvas do
- begin
- OldMode:= Pen.Mode;
- Pen.Mode:=pmXOr ;
- OldColor:=Pen.Color;
- Pen.Color:=clWhite;
- OldStyle:=Pen.Style;
- Pen.Style:=psdot;
- oldBStyle:=Brush.Style;
- Brush.Style:=bsClear;
- Case fMoveMode of
- mmNone:;
- { sPoint:;}
- mmZoom: If fLButtonDown then
- begin
- //tidy up
- If abs(fStartPos.SPt.X)>abs(fCurrentPos.SPt.X) then
- Begin
- X1:=(fCurrentPos.SPt.X); X2:=(fStartPos.SPt.X);
- end else
- Begin
- X2:=(fCurrentPos.SPt.X);X1:=(fStartPos.SPt.X);
- end;
-
- If fCurrentPos.SPt.Y>fStartPos.SPt.Y then
- Begin
- Y1:=fCurrentPos.SPt.Y; Y2:=fStartPos.SPt.Y;
- end else
- Begin
- Y2:=fCurrentPos.SPt.Y; Y1:=fStartPos.SPt.Y;
- end;
- Rectangle(X1,Y1,X2,Y2);
- If X<(fStartPos.SPt.X) then
- Begin
- X1:=X; X2:=(fStartPos.SPt.X);
- end else
- Begin
- X2:=X; X1:=(fStartPos.SPt.X);
- end;
- If Y<fStartPos.SPt.Y then
- Begin
- Y1:=Y; Y2:=fStartPos.SPt.Y;
- end else
- Begin
- Y2:=Y; Y1:=fStartPos.SPt.Y;
- end;
- Rectangle(X1,Y1,X2,Y2);
- end;
- mmPan: If fLButtonDown then
- begin
- MoveTo(fStartPos.SPt.X,fStartPos.SPt.Y);
- LineTo(fCurrentPos.SPt.X,fCurrentPos.SPt.Y);
- MoveTo(fStartPos.SPt.X,fStartPos.SPt.Y);
- LineTo(X,Y);
- end;
- mmMeasure:
- If (fMovePoints.Count>0) then
- Begin
- If not fFirstMove then
- Begin
- MoveTo(fStartPos.SPt.X,fStartPos.SPt.Y);
- LineTo(fCurrentPos.SPt.X,fCurrentPos.SPt.Y);
- end;
- MoveTo(fStartPos.SPt.X,fStartPos.SPt.Y);
- LineTo(X,Y);
- If not fFirstMove then
- Begin
- MoveTo(fCurrentPos.SPt.x,fCurrentPos.SPt.Y);
- LineTo(tLinkPoint(fMovePoints.Items[0]).SPt.X,
- tLinkPoint(fMovePoints.Items[0]).SPt.Y);
- end else
- fFirstMove:=False;
- MoveTo(X,Y);
- LineTo(tLinkPoint(fMovePoints.Items[0]).SPt.X,
- tLinkPoint(fMovePoints.Items[0]).SPt.Y);
- end;
- end;{Case}
- Pen.Mode:=OldMode;
- Pen.Style:=oldStyle;
- Brush.Style:=oldBStyle;
- Pen.Color:=OldColor;
- end;
- end else
- Begin
-
- end;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.DrawToolGuides(X,Y:LongInt);
- //draw the temporary mouse lines
- Var
- OldMode:TPenMode;
- oldStyle:TPenStyle;
- oldColor:TColor;
- oldBStyle:tBrushStyle;
- X1,X2,Y1,Y2:LongInt;
-
- Procedure DrawSegs;
- var i:longInt;
- SPos,EPos:tLinkPoint;
- Begin
- For i:=0 to fSelectPoints.Count-2 do
- Begin
- SPos:=tLinkPoint(fSelectPoints.Items[i]);
- EPos:=tLinkPoint(fSelectPoints.Items[i+1]);
- fCanvas.MoveTo(SPos.SPt.X,sPos.SPT.Y);
- fCanvas.LineTo(EPos.SPt.X,EPos.SPt.Y);
- end;
- end;
-
- Procedure DrawThePloy;
- Begin
- If (fSelectState=stPoly) and (fSelectPoints.Count>0) then
- Begin
- With fCanvas do
- begin
- OldStyle:=Pen.Style;
- Pen.Style:=psdot;
-
- DrawSegs;
-
- OldMode:= Pen.Mode;
- Pen.Mode:=pmXOr ;
- OldColor:=Pen.Color;
- Pen.Color:=clWhite;
- oldBStyle:=Brush.Style;
- Brush.Style:=bsClear;
-
- If not fClearedCurrentPos then
- Begin
- MoveTo(fStartPos.SPt.X,fStartPos.sPt.Y);
- LineTo(fCurrentPos.SPt.X,fCurrentPos.sPt.Y);
- end else
- fClearedCurrentPos:=False;
- MoveTo(fStartPos.SX,fStartPos.SPt.Y);
- LineTo(X,Y);
-
- Pen.Mode:=OldMode;
- Pen.Style:=oldStyle;
- Brush.Style:=oldBStyle;
- Pen.Color:=OldColor;
- end;
- end;
- end;
- Begin
- If (fToolMode=tlNone) or fViewAnimation then exit;
- If fGDIGeneric then
- Begin
- With fCanvas do
- begin
- OldMode:= Pen.Mode;
- Pen.Mode:=pmXOr ;
- OldColor:=Pen.Color;
- Pen.Color:=clWhite;
- OldStyle:=Pen.Style;
- Pen.Style:=psdot;
- oldBStyle:=Brush.Style;
- Brush.Style:=bsClear;
- Case fToolMode of
- tlPoint:;
- tlLine:
- begin
- If odd(fSelectPoints.Count) then
- Begin
- If not fClearedCurrentPos then
- Begin
- MoveTo(fStartPos.SX,GetWindowPos(fStartPos.SY));
- LineTo(fCurrentPos.SX,GetWindowPos(fCurrentPos.SY));
- end else
- fClearedCurrentPos:=False;
- MoveTo(fStartPos.SX,GetWindowPos(fStartPos.SY));
- LineTo(X,Y);
- end;
- end;
- tlPolyLine:
- Begin
- If not fClearedCurrentPos then
- Begin
- MoveTo(fStartPos.SX,GetWindowPos(fStartPos.SY));
- LineTo(fCurrentPos.SX,GetWindowPos(fCurrentPos.SY));
- end else
- fClearedCurrentPos:=False;
- MoveTo(fStartPos.SX,GetWindowPos(fStartPos.SY));
- LineTo(X,Y);
- end;
- tlPolyGon:
- Begin
- If not fClearedCurrentPos then
- Begin
- MoveTo(fStartPos.SX,GetWindowPos(fStartPos.SY));
- LineTo(fCurrentPos.SX,GetWindowPos(fCurrentPos.SY));
- end
- else
- fClearedCurrentPos:=False;
- MoveTo(fStartPos.SX,GetWindowPos(fStartPos.SY));
- LineTo(X,Y);
- If fSelectPoints.Count>0 then
- Begin
- MoveTo(fCurrentPos.SX,GetWindowPos(fCurrentPos.SY));
- LineTo(tLinkPoint(fSelectPoints.Items[0]).SX,
- GetWindowPos(tLinkPoint(fSelectPoints.Items[0]).SY));
- MoveTo(X,Y);
- LineTo(tLinkPoint(fSelectPoints.Items[0]).SX,
- GetWindowPos(tLinkPoint(fSelectPoints.Items[0]).SY));
- end;
- end;
- tlRectangle:
- begin
- If odd(fSelectPoints.Count) then Begin
- If not fClearedCurrentPos then Begin
- If (fStartPos.SX)>(fCurrentPos.SX) then Begin
- X1:=(fCurrentPos.SX);
- X2:=(fStartPos.SX);
- end
- else Begin
- X2:=(fCurrentPos.SX);
- X1:=(fStartPos.SX);
- end;
- If GetWindowPos(fStartPos.SY)>GetWindowPos(fCurrentPos.SY) then Begin
- Y1:=GetWindowPos(fCurrentPos.SY);
- Y2:=GetWindowPos(fStartPos.SY);
- end
- else begin
- Y2:=GetWindowPos(fCurrentPos.SY);
- Y1:=GetWindowPos(fStartPos.SY);
- end;
- Rectangle(X1,Y1,X2,Y2);
- end
- else
- fClearedCurrentPos:=False;;
- If X<(fStartPos.SX) then Begin
- X1:=X;X2:=(fStartPos.SX);
- end
- else Begin
- X2:=X;X1:=(fStartPos.SX);
- end;
- If Y<height-fStartPos.SY then Begin
- Y1:=Y;Y2:=GetWindowPos(fStartPos.SY);
- end
- else Begin
- Y2:=Y;Y1:=GetWindowPos(fStartPos.SY);
- end;
- Rectangle(X1,Y1,X2,Y2);
- end;
- end;
-
- end;{Case}
- Pen.Mode:=OldMode;
- Pen.Style:=oldStyle;
- Brush.Style:=oldBStyle;
- Pen.Color:=OldColor;
- If (fToolMode = tlSelect) and (fMoveMode=mmNone) then DrawThePloy;
- end;
- end else
- Begin
-
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DrawHUDDisplay;
- //draw the HUD screen data
- Var OldStyle:tBrushStyle;
- w,h:LongInt;
- Begin
- if fHRC=0 then exit;
- If fGDIGeneric then
- Begin
- OldStyle:=fCanvas.Brush.Style;
- fCanvas.Brush.Style:=bsClear;
- If fViewerTimer.enabled then
- If fHUDon then
- Begin
- DoHUDUpdate;
- // call user HUD update
- If Assigned(fOnHUDUpdate) then fOnHUDUpDate(self,fCanvas,fGDIGeneric);
- end;
- //tidy up
- fCanvas.Brush.Style:=OldStyle;
- end else
- Begin
- // set up the GLCanvas
- glCanvas.f3DMode:= False;
- //set background state
- CallList(fGeneralLists+dlForeGround);
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix;
- glLoadIdentity;
- If not fDrawToOther then
- Begin
- w:=width;h:=height;
- end else
- Begin
- w:=fOtherWidth;h:=fOtherHeight;
- end;
- gluOrtho2D(-w/2,w/2,-h/2,h/2);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity;
- glTranslatef(-w/2,-h/2,1);
-
- If fHUDon then
- Begin
- DoHUDUpdate;
- // call user HUD update
- If Assigned(fOnHUDUpdate) then fOnHUDUpDate(self,fCanvas,fGDIGeneric);
- end;
- // tidy up
- glCanvas.f3DMode:= True;
- glPopMatrix();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix;
- glMatrixMode(GL_MODELVIEW);
- end;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.UpdateExtraScreenCoordsLabel:String;
- var
- aStr,S1:String;
- Procedure GetDEltaData(aList:tList);
- Var DeltaX,DeltaY,DeltaZ,LastDistance,B,A:Double;
- lp1:tLinkPoint;
- P1,P2:tGLPoint;
- Begin
- If aList.Count=0 then exit;
- Lp1:=aList.Items[aList.count-1] ;
- DeltaX := MouseX-LP1.X; //dif in X
- DeltaY := MouseY-LP1.Y; //dif in Y
- DeltaZ := MouseZ-LP1.Z; //dif in Z
- LastDistance:=sqrt( sqr(DeltaX)+
- sqr(DeltaY)+
- sqr(DeltaY)); //Real dist
- P1.X:=LP1.X;P2.X:=MouseX;
- P1.Y:=LP1.Y;P2.Y:=MouseY;
- P1.Z:=LP1.Z;P2.Z:=MouseZ;
- aStr:=aStr+'DX= ';
- Str(DeltaX:-1:1,S1);
- aStr:=aStr+s1+', DY= ';
- Str(DeltaY:-1:1,S1);
- aStr:=aStr+s1+', DZ= ';
- Str(DeltaZ:-1:1,S1);
- aStr:=aStr+s1+', Dist= ' ;
- Str(LastDistance:-1:1,S1);
- iF BearingAndAzimuth(P1,P2,B,A) then
- Begin
- aStr:=aStr+s1+', Br= ' ;
- Str(B:-1:1,S1);
- aStr:=aStr+s1+', Az= ' ;
- Str(A:-1:1,S1);
- aStr:=aStr+s1;
- end else aStr:=aStr+s1;
-
- end;
- Begin
- If Assigned(fExtraData) then
- begin
- aStr:='';
- If fMoveMode<>mmNone then
- Case fMoveMode of
- mmMeasure: GetDeltaData(fMovePoints);
- end
- else
- If fToolMode<>tlNone then
- Case fToolMode of
- tlLine:GetDeltaData(fSelectPoints);
- end;
- fExtraData.Text:=aStr;
- Result:=aStr;
- end;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.UpdateScreenCoordsLabel:String;
- var
- aStr,S1:String;
- Begin
- Result:='';
- If Assigned(fLocationLabel) then
- Begin
- Str(MouseX:-1:1,S1);
- aStr:=aStr+s1+', ';
- Str(MouseY:-1:1,S1);
- aStr:=aStr+s1+', ';
- Str(MouseZ:-1:1,S1);
- aStr:=aStr+s1;
- fLocationLabel.Text:=aStr;
- Result:=aStr;
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.CopyCurrentView;
- // make a copy of the curent viewing position
- Begin
- fPreviousViews.Add(fViewer.Duplicate);
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.RestoreLastView;
- // restore the last viewing position
- Begin
- If fPreviousViews.Count=0 then exit;
- fViewer.CopyValuesFrom(fPreviousViews.Items[fPreviousViews.Count-1]);
- TViewFrame(fPreviousViews.Items[fPreviousViews.Count-1]).free;
- fPreviousViews.Delete(fPreviousViews.Count-1);
- SetUpViewingFrustrum;
- Repaint;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.GetScale:Single;
- Begin
- Result:=fViewer.Scale;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.getXCubeSize:Double;
- Begin
- Result:=fViewer.XRadius;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.getYCubeSize:Double;
- Begin
- Result:=fViewer.YRadius;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.getZCubeSize:Double;
- Begin
- Result:=fViewer.ZRadius;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.GetAnimation:Boolean;
- Begin
- Result:=fAnimationRunning;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.SetAnimation(aVal:Boolean);
- Begin
- If aVal then StartAnimation else StopAnimation;
- fAnimationRunning:=aVal;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.SetViewportGridOn(aVal:Boolean);
- Begin
- If aVal=fViewportGridOn then exit;
- fViewportGridOn:=aVal;
- Repaint;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.SetViewportGridTextOn(aVal:Boolean);
- Begin
- If aVal=fViewportGridTextOn then exit;
- fViewportGridTextOn:=aVal;
- Repaint;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.SetCursor3D(aVal:Boolean);
- Var P1,P2,P3:tGLPoint;
- Begin
- If aVal=f3DCursorOn then exit;
- f3DCursorOn:=aVal;
- CalcCursorPlane(P1,P2,P3,False);
- RePaint;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.SetStdDisplayList(aVal:Boolean);
- Begin
- If fStdDisplayList=aVal then exit;
- fStdDisplayList:=aVal;
- iF fStdDisplayList then
- Begin
- If not EnableGL then
- Begin
- fStdDisplayList:=False;
- exit;
- end;
- SetUpStdDisplayLists;
- BuildDisplayLists;
- end else
- Begin
- ShutDownStdDisplayLists;
- end;
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.StartAnimation;
- // start the animation timer
- Begin
- If (csDesigning in ComponentState) then
- Begin
- StopAnimation;
- exit;
- end;
- If Assigned(fAnimateTimer) then
- Begin
- fLastRenderMode:=fRenderMode;
- fRenderMode :=rmAnimation;
- fAnimateTimer.Enabled:=True;
- fViewPtIndex:=0;
- fClockStart :=TimeGetTime;
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.StopAnimation;
- // stop the animation timer
- Begin
- If Assigned(fAnimateTimer) then
- Begin
- fAnimateTimer.Enabled:=False;
- fRenderMode:=fLastRenderMode;
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.StartViewerAnimation;
- // start the animation timer
- Begin
- If assigned(fViewerTimer) then
- Begin
- fViewerTimer.Enabled:=True;
- fViewAnimation:=True;
- fViewClockStart:=TimeGetTime;
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.StopViewerAnimation;
- // stop the animation timer
- Begin
- If assigned(fViewerTimer) then
- Begin
- fViewerTimer.Enabled:=False;
- fViewAnimation:=False;
- end;
- end;
- (******* ******************************************************)
- Function TCustomOpenGLWindow.ProjectOnScreen(aPt:tGLPoint;
- var ScreenPt:TPoint;
- var ZDepth:GLDouble):Boolean;
- {Project the given point onto the screen of the given RC}
- Var Sc1,Sc2,ZD:GLDouble;
- MP,PP:pGLDouble;
- VP:PGLint;
- Begin
- Result:=False;
- MP:=pGLDouble(@fModelMatrix);
- PP:=pGLDouble(@fprojMatrix);
- VP:=pGLInt(@fViewPort);
- If (gluProject(aPt.X,aPt.Y,aPt.Z,MP,PP,VP,Sc1,Sc2,ZD)=GL_True) then
- Begin
- If (abs(SC1)>High(LongInt)) or (abs(sc2)>High(LongInt)) then exit;
- ScreenPt.X:=Round(SC1);
- ScreenPt.Y:=Round(SC2);
- ZDepth:=ZD;
- Result:=True;
- end;
- end;
- (******* ******************************************************)
- Function TCustomOpenGLWindow.ProjectLineOnScreen (var aPt1,aPt2 : tGLPoint):Boolean;
- // project the given 3D line ont the screen returning the modified tGLPoint
- // Values. Return true if sucessful
- Var CRM : GLint;
- TBuff: Array[0..7] of GLfloat;
- Res : LongInt;
- Begin
- REsult:=False;
- EnableGL;
- glGetIntegerv(GL_RENDER_MODE,@CRM);
- // if not in the right mode then quit
- If CRM<>GL_RENDER then exit;
-
- FillChar(tBuff,SizeOf(tBuff),0);
- // select the buffer
- glFeedbackBuffer(8,GL_3D,@tBuff);
- // set the mode
- glRenderMode(GL_FEEDBACK);
- // draw the line to the buffer
- GLBegin(GL_Lines);
- glVertex3Dv(@aPt1);
- glVertex3dv(@aPt2);
- glEnd;
- // switch back the mode
- Res := glRenderMode(GL_RENDER);
- If Res<0 then exit;
- // if failed to draw then exit
- If (tBuff[0]=0) then exit;
- // get the data
- aPt1.X:=tBuff[1];
- aPt1.Y:=tBuff[2];
- aPt1.Z:=tBuff[3];
-
- aPt2.X:=tBuff[4];
- aPt2.Y:=tBuff[5];
- aPt2.Z:=tBuff[6];
- // set result
- Result:=True;
- end;
- (******* ******************************************************)
- Function TCustomOpenGLWindow.GetFromScreen(var aPt:tGLPoint;
- ScreenPt:TPoint;
- ZDepth:GLDouble):Boolean;
- Var Sc1,Sc2,X,Y,Z:GLDouble;
- MP,PP:pGLDouble;
- VP:PGLint;
- Begin
- Result:=False;
- SC1:=ScreenPt.X;
- SC2:=ScreenPt.Y;
- MP:=pGLDouble(@fModelMatrix);
- PP:=pGLDouble(@fprojMatrix);
- VP:=pGLInt(@fViewPort);
- If (gluUnProject(Sc1,Sc2,ZDepth,MP,PP,VP,X,Y,Z)=GL_True)then
- Begin
- Result:=True;
- aPt.X:=X;
- aPt.Y:=Y;
- aPt.Z:=Z;
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.GetFrontBackPoints(const XVal,YVal:Longint;ZVal,ticht:Double;
- var Point,BackPt,FrontPt,ticPt:tGLPoint);
- // get the data to be able to draw line from front to back
- Var ScnPt: TPoint;
-
- Begin
- ScnPt.X:=XVal;
- ScnPt.Y:=YVal;
- GetFromScreen(Point,ScnPt,ZVal);
- GetFromScreen(BackPt,ScnPt,1.0);
- GetFromScreen(FrontPt,ScnPt,0.0);
- ScnPt.Y:=ScnPt.Y+Round(ticht);
- GetFromScreen(ticPt,ScnPt,ZVal);
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.MouseDown(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- Var ReDrawNeeded:Boolean;
- Procedure DoLeftButtonDown;
- Begin
- XDif:=0; XStart:=X;
- YDif:=0; YStart:=Y;
- fLButtonDown:=True;
-
- Case fMoveMode of
- mmMoveToPt : DoMove;
- mmLookAt,mmRotate,
- mmwalk,mmFly,mmslide,
- mmTwist : StartViewerAnimation;
- mmMeasure : DoMeasure(X,Y);
- mmModifyScreenZ : StartViewerAnimation;
- mmLookAtPt : DoLookAtPt;
- end;
- // handle selection
- If (fToolMode=tlSelect) then DoOnSelectDown(X,Y,ReDrawNeeded);
-
- If ReDrawNeeded then repaint;
- // store copy of viewer
- If fMoveMode<>mmNone then CopyCurrentView;
- end;
-
- Begin
- fShift:=Shift;
- EnableGL;
- If not (csDesigning in Componentstate) then
- Begin
- // modify the screen z position based on the current cursor plane
- UpDateScreenZ(X,Y,fViewer);
-
- fCurrentPos.SetWinScreenPt(X,y,height,fViewer.ScreenZ);
- ConvertScreenToWorld(fCurrentPos,False);
-
- Case Button of
- // do left button stuff
- mbLeft : DoLeftButtonDown;
- mbRight: fRButtonDown:=True;
- end; {Case}
-
- fStartPos.SetWinScreenPt(X,y,height,fViewer.ScreenZ);
- ConvertScreenToWorld(fStartPos,False);
-
- fViewClockStart:=TimeGetTime;
- end;
- // check for GLErrors
- GetError;
-
- Inherited ;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.UpDateScreenZ(X,Y:Longint;aViewer:TViewFrame);
- Begin
- If not f3DCursorOn then exit;
- If not assigned(aViewer) then exit;
- If (fCursorPlaneRec.C=0) or not fCursorPlaneRec.IsValid then exit;
- With fCursorPlaneRec do
- aViewer.ScreenZ:=(D-(A*X)-(B*(height-Y)))/C;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.CalcCursorPlane(aP1,aP2,aP3:tGLPoint;UseCustom:Boolean);
- // calc the required values for the cursor plane from P1,P2,P3);
- Var P1,P2,P3:tGLPoint;
- t1,t2,t3:tPoint;
- z1,z2,z3:GLDouble;
- Begin
- If UseCustom then
- Begin
- P1:=aP1;
- P2:=aP2;
- P3:=aP3;
- end else
- Case fViewMode of
- vmLookDown,vmLookUp:
- Begin
- //XY plane
- With P1 do begin X:=0;Y:=0;Z:=fHome.Z; end;
- With P2 do begin X:=CursorPlaneSide;Y:=0;Z:=fHome.Z; end;
- With P3 do begin X:=0;Y:=CursorPlaneSide;Z:=fHome.Z; end;
- end;
- vmLookWest,vmLookEast:
- Begin
- //YZ plane
- With P1 do begin X:=fHome.X;Y:=0;Z:=0; end;
- With P2 do begin X:=fHome.X;Y:=0;Z:=CursorPlaneSide; end;
- With P3 do begin X:=fHome.X;Y:=CursorPlaneSide;Z:=0; end;
- end;
- vwLookNorth,vmLookSouth:
- Begin
- //XZ plane
- With P1 do begin X:=0;Y:=fHome.Y;Z:=0; end;
- With P2 do begin X:=CursorPlaneSide;Y:=fHome.Y;Z:=0; end;
- With P3 do begin X:=0;Y:=fHome.Y;Z:=CursorPlaneSide; end;
- end;
- end;{Case}
- If ProjectOnScreen(P1,t1,z1)and
- ProjectOnScreen(P2,t2,z2)and
- ProjectOnScreen(P3,t3,z3)then
- Begin
- CalcPlaneEq(t1.x,t1.y,z1,
- t2.x,t2.y,z2,
- t3.x,t3.y,z3,
- fCursorPlaneRec);
- end;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.MouseMove(Shift: TShiftState; X, Y: Integer);
- var
- sDist:Single;
- aPt:tGLPoint;
- ReDrawNeeded:Boolean;
- Begin
- fShift:=Shift;
- ReDrawNeeded:=False;
- If Focused then
- Begin
-
- If fSnapOn then
- Begin
- aPt.X:=fCurrentPos.X;
- aPt.Y:=fCurrentPos.Y;
- aPt.Z:=fCurrentPos.Z;
- sDist:=DistanceBetween(fSnapPoint,aPt);
- If sDist<SnapDistance then
- SnapToPoint(fSnapPoint.X,fSnapPoint.Y,fSnapPoint.Z,Hint)
- else
- fSnapOn:=False;
- end;
-
- DrawToolGuides(X,Y);
- //draw the stuff for the current Tool mode
- DrawMoveGuides(X,Y);
- // draw the screen stuff for the current move mode
- UpDateScreenZ(X,Y,fViewer);
- fCurrentPos.SetWinScreenPt(X,y,height,fViewer.ScreenZ);
- ConvertScreenToWorld(fCurrentPos,False);
-
-
- If not (csDesigning in Componentstate) then
- Begin
- If fGDIGeneric then Draw3DGDICursor(glGridType(fViewmode))
- else repaint;
- If fLButtonDown and
- ((abs(X-fStartPos.SX)>MouseMoveTol) or
- (abs(Y-fStartPos.SY)>MouseMoveTol)) then
- Begin
- XDif:=(X-xStart);
- YDif:=(Y-yStart);
-
- Case fToolMode of
- tlNone:;
- tlSelect: If (fSelectState<>stnone) then DoSelectedMove(X,Y,ReDrawNeeded);
- end;
- If ReDrawNeeded then repaint; // should not be true
- end {if flButtonDown}
- else
- Begin
- UpdateScreenCoordsLabel;
- UpdateExtraScreenCoordsLabel;
- end;
- end; {Running}
- end {if Focussed}
- else
- Begin
- UpdateScreenCoordsLabel;
- UpdateExtraScreenCoordsLabel;
- end;
- {Draw cursor}
- Inherited MouseMove(Shift,X,Y);
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.MouseUp(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- Var RedrawNeeded:Boolean;
- begin
- If canFocus and not focused then SetFocus;
- fShift:=Shift;
- If not (csDesigning in Componentstate)then
- Begin
- UpDateScreenZ(X,Y,fViewer);
- fCurrentPos.SetWinScreenPt(X,y,height,fViewer.ScreenZ);
- ConvertScreenToWorld( fCurrentPos,False);
-
- fLastPos.SetWinScreenPt(X,y,height,fViewer.ScreenZ);
- ConvertScreenToWorld(fLastPos,False);
-
- If Button=MbLeft then
- Begin
- XDif:=(X-xStart);
- YDif:=(Y-yStart);
-
- If fLButtonDown and (fToolMode=tlSelect)and
- (fSelectState<>stnone) then DoSelectMoveFinish(X,Y,RedrawNeeded);
- { If ReDrawNeeded then repaint;}
-
- If (fToolMode<>tlNone) and (fMoveMode=mmNone) and
- focused then fSelectPoints.Add(fStartPos.Duplicate);
-
- Case fMoveMode of
- mmZoom : DoZoom;
- mmPan : DoPan;
- mmLookAt,
- mmFly,
- mmRotate,
- mmSlide,
- mmWalk,
- mmTwist : StopviewerAnimation;
- mmModifyScreenZ:StopViewerAnimation;
- end; {case}
-
- fLButtonDown:=false;
- Repaint;
- end
- else
- If Button=mbRight then fRButtonDown:=false;
- end;
- Inherited MouseUp(Button,Shift,X,Y);
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.Click;
- begin
- If CanFocus and Not focused then SetFocus;
- Inherited Click;
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.DblClick;
- Begin
-
- Inherited DblClick;
- end ;
- (*************************************************************)
- Function TCustomOpenGLWindow.WX:GLDouble;
- Begin
- Result:=fCurrentPos.X;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.WY:GLDouble;
- Begin
- Result:=fCurrentPos.Y;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.WZ:GLDouble;
- Begin
- Result:=fCurrentPos.Z;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.GetGLPerPixel:GLFloat;
- Begin
- //to do need to return a valid value if in perspective mode if possible
- {If fViewer.Perspective then result:=1 else }result:=fGLperPixel;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.GLSessionSetUp ;
- {Set up when GL session is started}
- Begin
- If fHRC=0 then exit;
- GLLock;
- If fBackColor=glWhiteBkgd then
- glClearColor(1.0,1.0,1.0,1.0)
- else
- glClearColor(0.0,0.0,0.0,1.0);
- glClearIndex(0.0);
- glClearDepth(1.0);
- glPixelStorei(GL_Unpack_Alignment,1);
- //specific for windows and byte alignment
- {glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);}
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT);
-
- glDisable(GL_SCISSOR_TEST);
- glDisable(GL_BLEND);
-
- If not assigned(fShareGL) and fStdDisplayList then
- BuildDisplayLists;
- // set up the basic view stuff
- ReSetView(True);
-
- fValidBuffer:=False;
- glUnLock;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.GLRender2DForeGround;
- {Allow for the 2D drawing with in the buffer
- Is called after the 3D render}
- var w,h:Longint;
- Begin
- // set up the GLCanvas
- glCanvas.f3DMode:= False;
- //set background state
- CallList(fGeneralLists+dlForeGround);
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix;
- glLoadIdentity;
- If not fDrawToOther then
- Begin
- w:=width;
- h:=height;
- end else
- Begin
- w:=fOtherWidth;
- h:=fOtherHeight;
- end;
- gluOrtho2D(-w/2,w/2,-h/2,h/2);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity;
- glTranslatef(-w/2,-h/2,1);
-
- DoGLRender2Dforeground;
- If Assigned(fOn2DForeGroundRender) then
- fOn2DForeGroundRender(Self,fRenderMode,glCanvas);
-
- // draw the controls borders
- If not fDrawToOther then DrawBorder;
- // tidy up
- glCanvas.f3DMode:= True;
- glPopMatrix();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix;
- glMatrixMode(GL_MODELVIEW);
-
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.GLRenderWindow(DoSwap:Boolean);
- Begin
- fCanvas.Lock;
- // lock the canvas from others
- Try
- If not fRebuildneeded then
- Begin
- If DoSwap then
- Begin
- //If swap copy is enabled then swap buffers else need to rebuild
- If fpfd_Swap_Copy and fValidBuffer and not fDrawToOther then
- //some systems allow for a buffer swap others not
- SwapBuffers(fRenderDC)
- // swapbuffers is the Windows implementation
- else
- fRebuildNeeded:=True;
- end;//doswap
- end;
-
- If fRebuildNeeded then
- Begin
- //Tidy up extra construction lines
- Clear3DCursor;
- DoMoveTidyUp;
-
- if f3DCursorOn and not fGDIGeneric then Cursor:=crnone;
- //setup the cursors
-
- fRebuildNeeded:=False;
- fValidBuffer :=False;
- //rest the flags
-
- If doswap then ClearScreen;
- // clear the Open GL screen buffers
-
- SetUpViewingTransform;
- // set up the viewing transform
-
- GetViewPortGrid(glGridType(fViewmode),20);
- // calculate the reference grid data
-
- SaveState(stDrawing);
- GLRender2DBackGround;
- RestoreState;
- // draw background - note save and restore of GL state
-
- glPushMatrix();
- SaveState(stAll);
- // set up the modelview transform for 3D drawing
- glListBase(0);
- // make sure Display list base is zero
- Case fRenderMode of
- rmQuick: CallList(fGeneralLists+dlQuickRenderMode);
- else CallList(fGeneralLists+dlFullRenderMode);
- end;
- // set GL state to handle current render mode
- Do3DRenderScene;
- // do the 3D rendering
- DrawSelectedPoints;
- //draw points selected via the tools
- DrawSimpleAxis;
- //draw the simple axis
- RestoreState;
- glPopMatrix();
- // tidy up after 3D render
-
- SaveState(stDrawing);
- GLRender2DForeGround;
- RestoreState;
- // Call the 2D paper space render rountine inc drawing border
-
- SaveState(stDrawing);
- DrawHUDDisplay;
- RestoreState;
- // need to tackle the HUD draw before the glflush swapbuffer
- //if not fGDIGeneric
-
- glFinish;
- // Flush the OpenGL Pipeline and wait for it to finish
-
- If DoSwap then
- Begin
- If not fDrawToOther then
- Begin
- If SwapBuffers(fRenderDC) and fGDIGeneric and fpfd_Swap_Copy
- then fValidBuffer:=True;
- end;
- end;
- // once finished all the rendering to the Back Buffer then need
- // to swap the rendered scene into the front buffer
- end;
- Finally
- if f3DCursorOn and not fGDIGeneric then Cursor:=crdefault;
- fCanvas.UnLock;
- // unlock the canvas
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.GLRender2DBackGround;
- {Allow for the 2D drawing with in the buffer
- Is called after the 3D render}
- var w,h:LongInt;
- Begin
-
- // set up the GLCanvas
- glCanvas.f3DMode:= False;
- //set background state
- CallList(fGeneralLists+dlBackground);
-
- If not fDrawToOther then
- Begin
- w:=width;
- h:=height;
- end else
- Begin
- w:=fOtherWidth;
- h:=fOtherHeight;
- end;
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix;
- glLoadIdentity;
- gluOrtho2D(-w/2,w/2,-h/2,h/2);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity;
- glTranslatef(-w/2,-h/2,0);
-
- // draw the grid if needed
- If fViewportGridOn then DrawViewPortGrid(fViewportGridTextOn);
-
- // do the render stuff
- DoGLRender2Dbackground;
- If Assigned(fOn2DbackgroundRender) then
- fOn2DbackgroundRender(Self,fRenderMode,glCanvas);
-
- glCanvas.f3DMode:= True;
- glPopMatrix();
- //tidy up
- glMatrixMode(GL_PROJECTION);
- glPopMatrix;
- glMatrixMode(GL_MODELVIEW);
- end;
- (*************************************************************)
- // cals to be overridden in descendants
- Procedure TCustomOpenGLWindow.DoGLRender2DForeGround;
- {Render the stock platform or fixed background}
- begin
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.Do3DRenderScene;
- {Render the scene - override MUST call inherited}
- begin
- Draw3DCursor(glGridType(fViewmode));
-
- If Assigned(f0nDrawRenderScene) then
- f0nDrawRenderScene(Self,fRenderMode,glCanvas);
- // call the assigned procedure
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoGLRender2Dbackground;
- // draw the background in descendant}
- begin
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoHUDUpdate;
- Procedure FrameRateString;
- Var s:String;
- Begin
- s:='';
- If fViewElapsedTime>0 then Str(1000/fViewElapsedTime:-1:1,s);
- fCanvas.TextOut(20,20,'Frame Rate = '+s+' fps');
- end;
- Procedure AnimateHUD;
- Var s,s1:String;
- Begin
- s:='0';
- If fElapsedTime>0 then Str(1000/fElapsedTime:-1:1,s);
- s1:= 'Animation Rate = '+s+' fps';
- fCanvas.TextOut(width-(fCanvas.TextWidth(s1)+20),20,s1);
- end;
- Procedure LookAtHUD;
- Begin
- FrameRateString;
- end;
- Procedure RotateHUD;
- Begin
- FrameRateString;
- end;
- Procedure FlyHUD;
- Begin
- FrameRateString;
- end;
-
- Procedure WalkHUD;
- Begin
- FrameRateString;
- end;
- Procedure SlideHUD;
- Begin
- FrameRateString;
- end;
- Procedure TwistHUD;
- Begin
- FrameRateString;
- end;
- Procedure MeasureHUD;
- Var s:String;
- aMeasRec:tMeasureRecord;
- Begin
- GetMeasurementData( aMeasRec );
- With aMeasRec do
- Begin
- Str(NoOfPoints:-1,s);
- fCanvas.TextOut(20,35, 'No Of Pts = '+s);
- Str(LastDeltaX:-1:2,s);
- fCanvas.TextOut(20,50, 'DeltaX = '+s);
- Str(LastDeltaY:-1:2,s);
- fCanvas.TextOut(20,65, 'DeltaY = '+s);
- Str(LastDeltaZ:-1:2,s);
- fCanvas.TextOut(20,80, 'DeltaZ = '+s);
- Str(LastDistance:-1:2,s);
- fCanvas.TextOut(20,95, 'Real Dist = '+s);
- Str(Lastbearing:-1:2,s);
- fCanvas.TextOut(20,110,'Bearing = '+s);
- Str(LastElevation:-1:2,s);
- fCanvas.TextOut(20,125,'Elevation = '+s);
- Str(DistanceSum:-1:2,s);
- fCanvas.TextOut(20,140,'Perimeter = '+s);
- Str(Area:-1:2,s);
- fCanvas.TextOut(20,155,'Area = '+s);
- Str(CMX:-1:2,s);
- fCanvas.TextOut(20,170,'CMX = '+s);
- Str(CMY:-1:2,s);
- fCanvas.TextOut(20,185,'CMY = '+s);
- Str(CMZ:-1:2,s);
- fCanvas.TextOut(20,200,'CMZ = '+s);
- end;
- end;
-
- begin
- If fGDIGeneric then
- Begin
- fCanvas.Brush.Style:=bsClear;
- fCanvas.Font.Color:=clLime;
- fCanvas.Pen.Color:=clLime;
-
- Case fMoveMode of
- mmLookAt : LookAtHUD;
- mmRotate : RotateHUD;
- mmFly : FlyHUD;
- mmWalk : WalkHUD;
- mmSlide : SlideHUD;
- mmTwist : TwistHUD;
- mmMeasure: MeasureHUD;
- end;
-
- If fRenderMode=rmAnimation then AnimateHUD;
-
- end else
- Begin
-
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoOnSelectDown(X,Y:Longint;Var ReDrawNeeded:Boolean);
- // always call inherited if overriding
- Begin
- ReDrawNeeded:=False;
- // handle poly selection mode
- If fSelectState=stnone then fSelectState:=stButtonDown;
-
- If assigned(fOnSelectDown) then
- With fCurrentPos do
- fOnSelectDown(Self,SPt.X,SPt.Y,X,Y,Z,ReDrawNeeded,fSelectState);
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoSelectedMove(X,Y:Longint;Var ReDrawNeeded:Boolean);
- // Used to manage the drag/stretch mouse move stuff
- Begin
- ReDrawNeeded:=False;
- // handle poly selectioin mode
- If (fSelectState=stButtonDown) and
- ((abs(xDif)>20) or
- (abs(YDif)>20) )then
- Begin
- ClearSelectList;
- fSelectState:=stPoly;
- fSelectPoints.add(fStartPos.Duplicate);
- end;
- If assigned(fOnSelectMove) then
- With fCurrentPos do
- fOnSelectMove(Self,SPt.X,SPt.Y,X,Y,Z,ReDrawNeeded,fSelectState);
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.SelectPolyClosed:Boolean;
- // test fselectlist for 'closed' poly select
- Var
- i: LongInt;
- lamba:Double;
- Begin
- Result:=False;
- If (fSelectPoints.count<4) then exit;
- { check if line crosses to form polygon }
- i:=0;
- while (i<fSelectPoints.count-3)and not Result do
- begin
- Result:=intersects(fCurrentPos.Sx,
- fCurrentPos.Sy,
- TLinkPoint(fSelectPoints.Items[fSelectPoints.count-1]).sx,
- TLinkPoint(fSelectPoints.Items[fSelectPoints.count-1]).sy,
- TLinkPoint(fSelectPoints.Items[i]).sx,
- TLinkPoint(fSelectPoints.Items[i]).sy,
- TLinkPoint(fSelectPoints.Items[i+1]).sx,
- TLinkPoint(fSelectPoints.Items[i+1]).sy,
- lamba);
- inc(i);
- end;
- end;
- (*************************************************************)
- (*
- Procedure TCustomOpenGLWindow.CancelSelectPoly;
- //cancel the select poly and clear the fselectlist
- Begin
- ClearSelectList;
- fSelectState:=stNone;
- end;
- *)
- (*************************************************************)
- Function TCustomOpenGLWindow.IsPointInsideSelectPoly(X,Y:LongInt):Boolean;
- Begin
- Result:=False;
- If fSelectPoints.Count=0 then exit;
- If fSelectState<>stPolyClosed then exit;
- Result:=IsPtInsideList(X,Y,fSelectPoints);
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.IsPointOutSideSelectPoly(X,Y:LongInt):Boolean;
- Begin
- Result:=not IsPointInsideSelectPoly(X,Y);
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoSelectMoveFinish(X,Y:Longint;Var ReDrawNeeded:Boolean);
- // When a drag/stretch ids finished
- Begin
- ReDrawNeeded:=False;
- //handle poly select mode
- If (fSelectState=stPoly) and SelectPolyClosed then
- fSelectState:=stPolyClosed;
-
- If assigned(fOnSelectUp) then
- With fCurrentPos do
- fOnSelectUp(Self,SPt.X,SPt.Y,X,Y,Z,ReDrawNeeded,fSelectState);
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoCustomViewSetUp;
- // handle the setup of the ModelView Matrix for vmCustomview
- Begin
- If assigned(fOnCustomViewSetUp) then
- fOnCustomViewSetUp(Self);
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoAnimate(Sender:tObject);
- //called by the animate timer
- Var DoRepaint:Boolean;
- t:DWord;
- Begin
- t:= TimeGetTime;
- DoRepaint:=False;
- fElapsedTime:=t-fClockStart;
- If (fElapsedTime>30) or fFullFrameRate then
- Begin
- //Animate viewpoints
- If fAnimateViewPt and
- (fFutureViews.Count>0) and
- (fViewPtIndex<fFutureViews.Count-1)then
- Begin
- FViewer.CopyValuesFrom(fFutureViews.Items[fViewPtIndex]);
- DoRepaint:=True;
- Inc(fViewPtIndex);
- If fViewPtLoop and (fViewPtIndex=fFutureViews.Count-1) then
- fViewPtIndex:=0;
- end;
- If Assigned(fOnAnimate) then
- fOnAnimate(Self,fElapsedTime,DoRepaint);
- // up date screen data if required
- if fHUDon then DoHUDUpdate;
- // temporary to force an update
- DoRepaint:=True;
- end;
- fClockStart:=t;
- If DoRepaint then Repaint;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DoViewerAnimate(Sender:tObject);
- //called by the view animate timer
- Var t:DWord;
- P1,P2,P3:tGLPoint;
- Begin
- t:= TimeGetTime;
- fViewElapsedTime:= t-fViewClockStart;
- If fFullFrameRate or (fViewElapsedTime>30) then
- Begin
- Case fMoveMode of
- mmMoveToPt : DoMove;
- mmLookAt : DoLookAt;
- mmRotate : DoRotate;
- mmSlide : DoSlide;
- mmWalk : DoWalk;
- mmFly : DoFly;
- mmTwist : DoTwist;
- mmLookAtPt : DoLookAtPt;
- mmModifyScreenZ:DoScreenZ;
- end;{Case}
- If fMoveMode<>mmNone then CalcCursorPlane(P1,P2,P3,False);
-
- fViewClockStart:= t;
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DrawMoveHint;
- // called during the GL draw
- Procedure DrawRotate;
- Var OldStyle: tBrushStyle;
- OldColor:tColor;
- X1,Y1,X2,Y2:LongInt;
- Begin
- If fGDIGeneric then
- Begin
- With fCanvas do
- Begin
- oldStyle:=Brush.Style;
- OldColor:=pen.Color;
- Brush.Style:=bsClear;
- pen.Color:=clLime;
- X1:=XStart+20;Y1:=YStart+20;
- X2:=XStart-20;Y2:=YStart-20;
- Ellipse( X1,Y1,X2,Y2);
- X1:=XStart+40;Y1:=YStart+40;
- X2:=XStart-40;Y2:=YStart-40;
- Ellipse( X1,Y1,X2,Y2);
- X1:=XStart+50;Y1:=YStart+50;
- X2:=XStart-50;Y2:=YStart-50;
- MoveTo(X1,YStart);LineTo(X2,YStart);
- MoveTo(XStart,Y1);LineTo(XStart,Y2);
- Brush.Style:=OldStyle;
- pen.Color:=OldColor;
- end;
- end else
- Begin
-
- end;
- end;
- Procedure DrawTwist;
- Var OldStyle: tBrushStyle;
- OldColor:tColor;
- X1,Y1,X2,Y2:LongInt;
- Begin
- If fGDIGeneric then
- Begin
- With fCanvas do
- Begin
- oldStyle:=Brush.Style;
- OldColor:=pen.Color;
- Brush.Style:=bsClear;
- pen.Color:=clLime;
-
- X1:=XStart+50; X2:=XStart-50;
- Y1:=YStart+10; Y2:=YStart-10;
- MoveTo(Xstart,Y1); LineTo(XStart,Y2);
- Y1:=YStart+5; Y2:=YStart-5;
- MoveTo(X1,Y1); LineTo(X1,Y2);
- MoveTo(X1,YStart); LineTo(X2,YStart);
- MoveTo(X2,Y1); LineTo(X2,Y2);
-
- Brush.Style:=OldStyle;
- pen.Color:=OldColor;
- end;
- end else
- Begin
-
- end;
- end;
- Procedure DrawScreenZ;
- Var Fr,Bk,Pt,Tic:tGLPoint;
- FRP,BKP,PTP,TicP:TPoint;
- ZVal:Double;
- OldStyle: tBrushStyle;
- OldColor:tColor;
- Begin
- GetFrontBackPoints(XStart,YStart,fViewer.screenZ,10,Pt,Bk,Fr,Tic);
- If fGDIGeneric then
- Begin
- With fCanvas do
- Begin
- ProjectOnScreen(Fr,FRP,ZVal);
- bk.X:=Fr.X;bk.Y:=Fr.Y;
- ProjectOnScreen(Bk,BKP,ZVal);
- ProjectOnScreen(Pt,PTP,ZVal);
- ProjectOnScreen(Tic,TicP,ZVal);
-
-
- oldStyle:=Brush.Style;
- OldColor:=pen.Color;
- Brush.Style:=bsClear;
- pen.Color:=clLime;
-
- MoveTo(FRP.X,FRP.Y);
- LineTo(BKP.X,BKP.Y);
- MoveTo(XStart,YStart);
- LineTo(PTP.X,PTP.Y+10);
-
- Brush.Style:=OldStyle;
- pen.Color:=OldColor;
- end;
- end else
- Begin
-
- end;
- end;
-
- Begin
- If not fLButtonDown then exit;
- Case fMoveMode of
- mmLookAt,mmRotate,mmWalk,mmFly,mmslide: DrawRotate;
- mmTwist:DrawTwist;
- mmModifyScreenZ:DrawScreenZ;
- end;{Case}
- end;
- (*************************************************************)
- procedure TCustomOpenGLWindow.PaintWindow(DC: HDC);
- Begin
- If not fStartUpLoop then
- Begin
- ReSetView(True);// need to reset for some systems on the first paint
- fStartUpLoop:=True; //set flag for painetd once
- end;
- if fHRC=0 then
- Begin
- fRebuildNeeded:=True;
- fRePaintneeded:=True;
- fValidBuffer:=False;
- GDIPaintWindow(DC);
- end else
- Begin
- Try
- GLLock;
- // lock this procedure
- EnableGL;
- // activeate the Render Context if needed
- fOldMask:=MaskX86Exceptions;
- // mask for divide by zero exceptions
- GLRenderWindow(True);
- //Render the view
- Finally
- //replace divide by zero mask
- RestoreX86Mask(fOldMask);
- // unlock the GL session
- GLUnLock;
- // check for GLErrors
- GetError;
- // handle all the GDI paint stuff
- GDIPaintWindow(DC);
- end;
- end;
- end;
- (*************************************************************)
- (*
- Procedure TCustomOpenGLWindow.TextOut3D(anX,anY,anZ:glDouble;aSize:glFloat;aStr:String);
- // use the current base font to draw string
- Begin
- If length(aStr)>255 then exit;
- glListBase(fDefaultTextID);
-
- glPushMatrix;
- glTranslatef(anX,anY,anZ);
- glScalef(aSize,aSize,aSize);
- glCallLists(length(aSTR),GL_Unsigned_Byte,@aStr[1]);
- glPopMatrix;
- glListBase(0);
- end;
- *)
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DrawBorder;
- Begin
- If Focused then
- CallList(fGeneralLists+dlFocusedBorder) ;
- (* else
- glCallList(fGeneralLists+dlUnFocusedBorder);*)
- end;
- {**********************************************************}
- Procedure TCustomOpenGLWindow.ConvertScreenToWorld(aLinkPt:TLinkPoint;UseFar:Boolean);
- var WP:tGLPoint;
- SP:TPoint;
- TB:Boolean;
- Begin
- If not assigned(aLinkPt) then exit;
- SP.X:=aLinkPt.SX;
- SP.Y:=aLinkPt.SY;
- If not useFar then
- TB:=GetFromScreen(WP,SP,aLinkPt.ScreenZ)
- else
- TB:=GetFromScreen(WP,SP,1);
- If TB then
- Begin
- aLinkPt.X:=WP.X;
- aLinkPt.Y:=WP.Y;
- aLinkPt.Z:=WP.Z;
- end;
- end;
- {**********************************************************}
- Procedure TCustomOpenGLWindow.ConvertWorldToScreen(aLinkPt:TLinkPoint);
- var WP:tGLPoint;
- SP:TPoint;
- Begin
- If not assigned(aLinkPt) then exit;
- WP.X:=aLinkPt.X;
- WP.Y:=aLinkPt.Y;
- WP.Z:=aLinkPt.Z;
- aLinkPt.fScreenPtValid:=ProjectOnScreen(WP,SP,aLinkPt.ScreenZ);
- If aLinkPt.fScreenPtValid then
- begin
- aLinkPt.SX:=SP.x;
- aLinkPt.SY:=SP.Y;
- aLinkPt.SPt.X:=SP.X;
- aLinkPt.SPt.Y:=height-SP.Y;
- end;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.UpdateScreenPos;
- //will update all the LinkPoint screen positions
- Var I:LongInt;
- P1,P2:tGLPoint;
- S1,S2:tPoint;
- testDist:Integer;
- calcdist:Double;
- w,h:Longint;
- Begin
- EnableGL;
-
- ConvertWorldToScreen(fStartPos);
- ConvertWorldToScreen(fLastPos);
- ConvertWorldToScreen(fCurrentPos);
-
- For i:=0 to fSelectPoints.Count-1 do
- ConvertWorldToScreen(tLinkPoint(fSelectPoints.Items[I]));
- For i:=0 to fMovePoints.Count-1 do
- ConvertWorldToScreen(tLinkPoint(fMovePoints.Items[I]));
-
- //Set the fGLPerPixel value, use the centre value 0.5
- TestDist:=1000;
- If fDrawToOther then
- Begin
- w:=fOtherWidth;h:=fOtherHeight;
- end else
- Begin
- w:=Width;h:=Height;
- end;
- With s1 do begin X:=w div 2;y:=h div 2;end;
- With s2 do begin X:=(w div 2)+Testdist;y:=h div 2;end;
- If GetFromScreen(P1,S1,0.5) and GetFromScreen(P2,S2,0.5) then
- Begin
- CalcDist:= sqrt(sqr(P1.X-P2.X)+ sqr(P1.Y-P2.Y)+sqr(P1.Z-P2.Z));
- fGLperPixel:=CalcDist/TestDist;
- end;
- // check for GLErrors
- GetError;
- end;
- (***********************************************)
- Procedure TCustomOpenGLWindow.Clear3DCursor;
- Begin
- fZLineSet:=False;
- fYLineSet:=False;
- fXLineSet:=False;
- fZLStart.X:=0;fZLStart.Y:=0;
- fZLend.X:=0;fZLend.Y:=0;
- fyLStart.X:=0;fyLStart.Y:=0;
- fyLend.X:=0;fyLend.Y:=0;
- fxLStart.X:=0;fxLStart.Y:=0;
- fxLend.X:=0;fxLend.Y:=0;
- end;
- (***********************************************)
- Procedure TCustomOpenGLWindow.Draw3DGDICursor(aGridType:GLGridType);
- // draw the CAD style cross hairs
- Var X1,X2,Y1,Y2,Z1,Z2,fmin,fmax:tGLPoint;
- OldMode:TPenMode;
- oldStyle:TPenStyle;
- oldColor:TColor;
- oldBStyle:tBrushStyle;
- RefVal:GLDouble;
-
- Begin
- If not f3DCursorOn then exit;
- If (fMoveMode<>mmNone) and (ssLeft in fShift) then exit;
-
- With Canvas do
- Begin
- OldMode:= Pen.Mode;
- Pen.Mode:=pmXOr ;
- OldColor:=Pen.Color;
- Pen.Color:=clWhite;
- oldBStyle:=Brush.Style;
- oldStyle:=Pen.Style;
- Brush.Style:=bsClear;
-
- fMin:=Viewer.MinViewPrism(Grid_Scale);
- fMax:=Viewer.MaxViewPrism(Grid_Scale);
- //Z line
- Case aGridType of
- gtBottom,gtTop:
- Begin
- RefVal:=fHome.Z;
- Z1.X:=fCurrentPos.X;Z1.Y:=fCurrentPos.Y;Z1.Z:=RefVal;
- Z2.X:=fCurrentPos.X;Z2.Y:=fCurrentPos.Y;Z2.Z:=fCurrentPos.Z;
- Y1.X:=fmin.X;Y1.Y:=fCurrentPos.Y;Y1.Z:=RefVal;
- Y2.X:=fmax.X;Y2.Y:=fCurrentPos.Y;Y2.Z:=RefVal;
- X1.X:=fCurrentPos.X;X1.Y:=fmin.Y;X1.Z:=RefVal;
- X2.X:=fCurrentPos.X;X2.Y:=fmax.Y;X2.Z:=RefVal;
- end;
- gtLeftSide,gtRightSide:
- Begin
- RefVal:=fHome.X;
- Z1.X:=RefVal;Z1.Y:=fCurrentPos.Y;Z1.Z:=fCurrentPos.Z;
- Z2.X:=fCurrentPos.X;Z2.Y:=fCurrentPos.Y;Z2.Z:=fCurrentPos.Z;
- Y1.X:=RefVal;Y1.Y:=fCurrentPos.Y;Y1.Z:=fmin.Z;
- Y2.X:=RefVal;Y2.Y:=fCurrentPos.Y;Y2.Z:=fmax.Z;
- X1.X:=RefVal;X1.Y:=fmin.Y;X1.Z:=fCurrentPos.z;
- X2.X:=RefVal;X2.Y:=fmax.Y;X2.Z:=fCurrentPos.Z;
- end;
- gtBack,gtFront:
- Begin
- RefVal:=fHome.Y;
- Z1.X:=fCurrentPos.X;Z1.Y:=RefVal;Z1.Z:=fCurrentPos.Z;
- Z2.X:=fCurrentPos.X;Z2.Y:=fCurrentPos.Y;Z2.Z:=fCurrentPos.Z;
- Y1.X:=fmin.X;Y1.Y:=RefVal;Y1.Z:=fCurrentPos.Z;
- Y2.X:=fmax.X;Y2.Y:=RefVal;Y2.Z:=fCurrentPos.Z;
- X1.X:=fCurrentPos.X;X1.Y:=RefVal;X1.Z:=fmin.Z;
- X2.X:=fCurrentPos.X;X2.Y:=RefVal;X2.Z:=fmax.Z;
- end;
- end;{Case}
- If fZLineSet then
- Begin
- MoveTo(fZLStart.X,fZLStart.Y);
- LineTo(fZLEnd.X,fZLEnd.Y);
- end;
- If ProjectLineOnScreen(Z1,Z2) then
- Begin
- fZLStart.X:=Trunc(Z1.x);fZLStart.Y:=height-Trunc(Z1.Y);
- fZLend.X:=Trunc(Z2.x);fZLend.Y:=height-Trunc(Z2.Y);
- MoveTo(fZLStart.X,fZLStart.Y);LineTo(fZLEnd.X,fZLEnd.Y);
- fZLineSet:=True;
- end else fZLineSet:=False;
- //X line
-
- If fXLineSet then
- Begin
- MoveTo(fXLStart.X,fXLStart.Y);
- LineTo(fXLEnd.X, fXLEnd.Y);
- end;
- If ProjectLineOnScreen(X1,X2) then
- Begin
- fXLStart.X:=Trunc(X1.x);fXLStart.Y:=height-Trunc(X1.Y);
- fXLend.X:=Trunc(X2.x);fXLend.Y:=height-Trunc(X2.Y);
- MoveTo(fXLStart.X,fXLStart.Y);LineTo(fXLEnd.X, fXLEnd.Y);
- fXLineSet:=True;
- end else fXLineSet:=False;
- //Y line
-
- If fYLineSet then
- Begin
- MoveTo(fYLStart.X,fYLStart.Y);
- LineTo(fYLEnd.X, fYLEnd.Y);
- end;
- If ProjectLineOnScreen(Y1,Y2) then
- Begin
- fYLStart.X:=Trunc(Y1.x);fYLStart.Y:=height-Trunc(Y1.Y);
- fYLend.X:=Trunc(Y2.x);fYLend.Y:=height-Trunc(Y2.Y);
- MoveTo(fYLStart.X,fYLStart.Y);LineTo(fYLEnd.X, fYLEnd.Y);
- fYLineSet:=True;
- end else fYLineSet:=False;
-
- Pen.Mode:=OldMode;
- Pen.Style:=oldStyle;
- Brush.Style:=oldBStyle;
- Pen.Color:=OldColor;
- end;
- end;
- (***********************************************)
- Procedure TCustomOpenGLWindow.Draw3DCursor(aGridType:GLGridType);
- // draw the CAD style cross hairs
- Var X1,X2,Y1,Y2,Z1,Z2,fmin,fmax:tGLPoint;
- RefVal:GLDouble;
-
- Begin
- If not f3DCursorOn then exit;
- If fGDIGeneric then exit;
- If (fMoveMode<>mmNone) and (ssLeft in fShift) then exit;
-
- fMin:=Viewer.MinViewPrism(Grid_Scale);
- fMax:=Viewer.MaxViewPrism(Grid_Scale);
-
- With GLCanvas do
- Begin
-
- //Z line
- Case aGridType of
- gtBottom,gtTop:
- Begin
- RefVal:=fHome.Z;
- Z1.X:=fCurrentPos.X;Z1.Y:=fCurrentPos.Y;Z1.Z:=RefVal;
- Z2.X:=fCurrentPos.X;Z2.Y:=fCurrentPos.Y;Z2.Z:=fCurrentPos.Z;
- Y1.X:=fmin.X;Y1.Y:=fCurrentPos.Y;Y1.Z:=RefVal;
- Y2.X:=fmax.X;Y2.Y:=fCurrentPos.Y;Y2.Z:=RefVal;
- X1.X:=fCurrentPos.X;X1.Y:=fmin.Y;X1.Z:=RefVal;
- X2.X:=fCurrentPos.X;X2.Y:=fmax.Y;X2.Z:=RefVal;
- end;
- gtLeftSide,gtRightSide:
- Begin
- RefVal:=fHome.X;
- Z1.X:=RefVal;Z1.Y:=fCurrentPos.Y;Z1.Z:=fCurrentPos.Z;
- Z2.X:=fCurrentPos.X;Z2.Y:=fCurrentPos.Y;Z2.Z:=fCurrentPos.Z;
- Y1.X:=RefVal;Y1.Y:=fCurrentPos.Y;Y1.Z:=fmin.Z;
- Y2.X:=RefVal;Y2.Y:=fCurrentPos.Y;Y2.Z:=fmax.Z;
- X1.X:=RefVal;X1.Y:=fmin.Y;X1.Z:=fCurrentPos.z;
- X2.X:=RefVal;X2.Y:=fmax.Y;X2.Z:=fCurrentPos.Z;
- end;
- gtBack,gtFront:
- Begin
- RefVal:=fHome.Y;
- Z1.X:=fCurrentPos.X;Z1.Y:=RefVal;Z1.Z:=fCurrentPos.Z;
- Z2.X:=fCurrentPos.X;Z2.Y:=fCurrentPos.Y;Z2.Z:=fCurrentPos.Z;
- Y1.X:=fmin.X;Y1.Y:=RefVal;Y1.Z:=fCurrentPos.Z;
- Y2.X:=fmax.X;Y2.Y:=RefVal;Y2.Z:=fCurrentPos.Z;
- X1.X:=fCurrentPos.X;X1.Y:=RefVal;X1.Z:=fmin.Z;
- X2.X:=fCurrentPos.X;X2.Y:=RefVal;X2.Z:=fmax.Z;
- end;
- end;{Case}
- //Z Line
-
- MoveTo(Z1);
- LineTo(Z2);
- //X line
- MoveTo(X1);
- LineTo(X2);
- //Y line
- MoveTo(Y1);
- LineTo(Y2);
- end;
- end;
- (***********************************************)
- Procedure TCustomOpenGLWindow.GetViewPortGrid(aGridType:GLGridType;aStep:LongInt);
- var Linestart,LineEnd,fMin,fMax :tGLPoint;
- aRect:tRect;
- StartValX,StartValY,StartValZ,IncX,IncY,IncZ:Double;
- NoIncX,NoIncY,NoIncZ,Step:Smallint;
- CRM : GLint;
- i:Longint;
- // manage the feedback buffer data
-
-
- Procedure MakeLine(aVal:Double);
- var P1,P2:PGLPoint;
- Begin
- GetMem(P1,SizeOf(tGLPoint));
- P1^:=LineStart;
- GetMem(P2,SizeOf(tGLPoint));
- P2^:=LineEnd;
- If ProjectLineOnScreen(P1^,P2^) then
- Begin
- P1^.Z:=aVal;
- P2^.Z:=aVal;
- fGridPointsList.add(p1);
- fGridPointsList.add(p2);
- end else
- Begin
- FreeMem(P1,SizeOf(tGLPoint));
- FreeMem(P2,SizeOf(tGLPoint));
- end;
- end;
-
- Procedure BottomTop(CommonVal:Double);
- Var Count:LongInt;
- Begin
- SetGLPointVal(LineStart,StartValX,StartValY,CommonVal);
- SetGLPointVal(LineEnd,StartValX,StartValY+(IncY*NoIncY),CommonVal);
- For Count:=0 to NoIncX do
- Begin
- MakeLine(LineStart.X);
- LineStart.X:=LineStart.X+IncX;
- LineEnd.X :=LineEnd.X+incX;
- end;
- //2nd series vary Y horizontal lines
- SetGLPointVal(LineStart,StartValX,StartValY,CommonVal);
- SetGLPointVal(LineEnd,StartValX+(IncX*NoIncX),StartValY,CommonVal);
- For Count:=0 to NoIncY do
- Begin
- MakeLine(LineStart.Y);
- LineStart.Y:=LineStart.Y+IncY;
- LineEnd.Y:=LineEnd.Y+incY;
- end;
- end;
-
- Procedure LeftRight(CommonVal:Double);
- // pass in constant x
- Var Count:LongInt;
- Begin
- SetGLPointVal(LineStart,CommonVal,StartValY,StartValZ);
- SetGLPointVal(LineEnd,CommonVal,StartValY+(IncY*NoIncY),StartValZ);
- For Count:=0 to NoIncZ do
- Begin
- MakeLine(LineStart.Z);
- LineStart.Z:=LineStart.Z+IncZ;
- LineEnd.Z:=LineEnd.Z+incZ;
- end;
- //2nd series vary Y horizontal lines
- SetGLPointVal(LineStart,CommonVal,StartValY,StartValZ);
- SetGLPointVal(LineEnd,CommonVal,StartValY,StartValZ+(IncZ*NoIncZ));
- For Count:=0 to NoIncY do
- Begin
- MakeLine(LineStart.Y);
- LineStart.Y:=LineStart.Y+IncY;
- LineEnd.Y:=LineEnd.Y+incY;
- end;
- end;
- Procedure FrontBack(CommonVal:Double);
- // pass in constant Y
- Var Count:LongInt;
- Begin
- //first series Vertical lines Vary Z
- SetGLPointVal(LineStart,StartValX,CommonVal,StartValZ);
- SetGLPointVal(LineEnd,StartValX+(IncX*NoIncX),CommonVal,StartValZ);
- For Count:=0 to NoIncZ do
- Begin
- MakeLine(LineStart.Z);
- LineStart.Z:=LineStart.Z+IncZ;
- LineEnd.Z :=LineEnd.Z +incZ;
- end;
- //2nd series vary X horizontal lines
- SetGLPointVal(LineStart,StartValX,CommonVal,StartValZ);
- SetGLPointVal(LineEnd,StartValX,CommonVal,StartValZ+(IncZ*NoIncZ));
- For Count:=0 to NoIncX do
- Begin
- MakeLine(LineStart.X);
- LineStart.X:=LineStart.X+IncX;
- LineEnd.X :=LineEnd.X +incX;
- end;
- end;
-
- Begin
-
- glGetIntegerv(GL_RENDER_MODE,@CRM);
- // if not in the right mode then quit
- If CRM<>GL_RENDER then exit;
-
- {If perspective then exit;}
- If Not fDrawToOther then
- Begin
- With aRect do
- Begin
- Left:=0;Top:=0;Right:=width; Bottom:=height;
- end;
- end else
- Begin
- With aRect do
- Begin
- Left:=0;Top:=0;Right:=fOtherWidth;Bottom:=fOtherHeight;
- end;
- end;
- //clear the last list
- For i:=0 to fGridPointsList.count-1 do
- FreeMem(fGridPointsList.Items[i],SizeOf(tGLPoint));
- fGridPointsList.Clear;
- If astep<=0 then step:=8 else step:=aStep;
-
- fMin:=Viewer.MinViewPrism(Grid_Scale);
- fMax:=Viewer.MaxViewPrism(Grid_Scale);
- //first series Vertical lines Vary X
- Scale_Data(fMin.X,fMax.X,Step,StartValX,IncX,NoIncX);
- //first series Vertical lines Vary Y
- Scale_Data(fMin.Y,fMax.Y,Step,StartValY,IncY,NoIncY);
- //first series Vertical lines Vary Y
- Scale_Data(fMin.Z,fMax.Z,Step,StartValZ,IncZ,NoIncZ);
- // get the final clipped data
-
- If Perspective then
- Begin
- //Use the centre for the grid values
- Case aGridtype of
- gtBottom,gtTop : BottomTop(fHome.Z);
- gtLeftSide,gtRightSide: LeftRight(fHome.X);
- gtBack,gtFront : FrontBack(fHome.Y);
- end;
- end else
- Begin
- Case aGridtype of
- gtBottom,gtTop : BottomTop(fMin.Z);
- gtLeftSide,gtRightSide: LeftRight(fMin.X);
- gtBack,gtFront : FrontBack(fMin.Y);
- end;
- end;
- end;
- (***********************************************)
- Procedure TCustomOpenGLWindow.DrawViewPortGrid(IncText:Boolean);
- Var i:LongInt;
- p1,P2:tGLPoint;
- aVal:Double;
- s:String;
- Begin
- If fGridPointsList.Count=0 then exit;
- glCanvas.LineWidth:=1;
- glCanvas.Color:=glGray60;
- glCanvas.LineStyle:=stDotted4;
- i:=0;
- Repeat
- P1:= pGLPoint(fGridPointsList.Items[i])^;
- P2:= pGLPoint(fGridPointsList.Items[i+1])^;
- aVal:=P1.Z;
- P1.Z:=0;P2.Z:=0;
- glCanvas.MoveTo(P1);
- glCanvas.LineTo(P2);
- Str(aVal:-1:0,s);
- If IncText then
- Begin
- If P1.Y>p2.Y then
- Begin
- P2.Y:=P2.Y+5;
- P2.X:=P2.X+5;
- glCanvas.TextOut2D(P2,1,s);
- end else
- Begin
- P1.Y:=P1.Y+5;
- P1.X:=P1.X+5;
- glCanvas.TextOut2D(P1,1,s);
- end;
- end;
- P1.Z:=aVal;P2.Z:=aVal;
- i:=i+2;
- until i>= fGridPointsList.Count-1;
- glCanvas.Color:=glBlack;
- glCanvas.LineStyle:=stContinous;
- end;
-
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DrawSimpleAxis;
- //draw a simple X,Y,Z axis
- Var setpoint,StartPoint,endPoint1,endpoint2,endpoint3:tGLPoint;
- aPt:tPoint;
- aSizeMult,pixval:Single;
- Begin
- If not fSimpleAxis {or perspective} then exit;
- // set up for the L state in display list
- glCanvas.LineWidth:=1;
- aPt.X:=50;
- aPt.Y:=50;
- pixval:=UnitsPerPixel/2;
- GetFromScreen(setpoint,aPt,0.5);
- aSizeMult:=50*pixval;
- glLineWidth(1.0);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_LINE_SMOOTH);
- {glScalef(UnitsPerPixel,UnitsPerPixel,UnitsPerPixel);}
- glTranslatef(setpoint.X,setpoint.Y,setpoint.Z);
- startPoint.X:=0;startPoint.Y:=0;startPoint.Z:=0;
- endpoint1.X:=aSizeMult;endpoint1.Y:=0;endpoint1.Z:=0;
- endpoint2.X:=0;endpoint2.Y:=aSizeMult;endpoint2.Z:=0;
- endpoint3.X:=0;endpoint3.Y:=0;endpoint3.Z:=aSizeMult;
- glBegin(GL_LINES);
- glColor4fv(@glRed);
- glVertex3dv(@startpoint);
- glVertex3dv(@endpoint1);
- glVertex3d(55*pixval,13*pixval,0);
- glVertex3d(55*pixval,-13*pixval,0);
- glVertex3d(55*pixval,13*pixval,0);
- glVertex3d(80*pixval,13*pixval,0);
- glVertex3d(55*pixval,-13*pixval,0);
- glVertex3d(80*pixval,-13*pixval,0);
- glVertex3d(55*pixval,0,0);
- glVertex3d(75*pixval,0,0);
- glColor4fv(@glBlue);
- glVertex3dv(@startpoint);
- glVertex3dv(@endpoint2);
- glVertex3d(-13*pixval,55*pixval,0);
- glVertex3d(-13*pixval,80*pixval,0);
- glVertex3d(-13*pixval,80*pixval,0);
- glVertex3d(13*pixval,55*pixval,0);
- glVertex3d(13*pixval,55*pixval,0);
- glVertex3d(13*pixval,80*pixval,0);
- glColor4fv(@glGreen);
- glVertex3dv(@startpoint);
- glVertex3dv(@endpoint3);
- glend;
-
-
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.DrawSelectedPoints;
- //Draw the selected points according to current draw mode}
- Var I:LongInt;
- aPt:tLinkPoint;
- Begin
- {If fViewAnimation then exit;}
- { If or (fToolMode=tlNone) then exit;}
- //Set up draw mode
- saveState(stDrawing);
- If (fSelectPoints.Count>0) then
- Begin
- glLineWidth(1.0);
- glLineStipple(3, stDotted1);
- glColor4fv(@glBlack);
- glPointSize(2);
- Case fToolMode of
- tlPoint:glBegin(GL_Points);
- tlLine:glBegin(GL_LINES);
- tlPolyLine:glBegin(GL_LINE_STRIP);
- tlPolygon:glBegin(GL_LINE_LOOP);
- end;
- //Loop through points and draw
- If fToolMode<>tlRectangle then
- Begin
- For i:=0 to fSelectPoints.Count-1 do
- Begin
- aPt:=tLinkPoint(fSelectPoints.Items[I]);
- glVertex3dv(aPt.GetWorldPt);
- end;
- glEnd;
- end;
- end;
- IF (fMoveMode=mmMeasure) and (fMovePoints.Count>0) then
- Begin
- {dRAW THE MEASURE LINES}
- glLineWidth(1.0);
- glLineStipple(3, stDotted1);
- glColor4fv(@glLime);
- glBegin(GL_LINE_LOOP);
- //Loop through points and draw
- For i:=0 to fMovePoints.Count-1 do
- Begin
- aPt:=tLinkPoint(fMovePoints.Items[I]);
- glVertex3dv(aPt.GetWorldPt);
- end;
- glEnd;
- end;
- RestoreState;
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.GetGLVendor:pchar;
- Begin
- Result:=GetGLStringValue(GL_Vendor);
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.GetGLRenderer:pchar;
- Begin
- Result:=GetGLStringValue(GL_RENDERER);
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.GetGLVersion:pchar;
- Begin
- Result:=GetGLStringValue(GL_VERSION);
- end;
- (*************************************************************)
- Function TCustomOpenGLWindow.GetGLExtensions:pchar;
- Begin
- Result:=GetGLStringValue(GL_EXTENSIONS);
- end;
- (*************************************************************)
- function TCustomOpenGLWindow.GetPalette: HPALETTE;
- Begin
- Result:=fGLPalette;
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.SetMode(aMode:GLMoveMode);
- Begin
- If fMoveMode=aMode then exit;
- fMoveMode:=aMode;
- Repaint;
- end;
- (**************************************************************)
- Procedure TCustomOpenGLWindow.Clearscreen;
- //clear all the glbuffers
- Begin
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT );
- end;
- (**************************************************************)
- Procedure TCustomOpenGLWindow.UpdateScreenDisplayLists;
- //call when screen size change
-
- const
- EdgeOff=0;
- var w,h:Longint;
- Begin
- if fGeneralLists=0 then exit;
- If not EnableGL then exit;;
- glListBase(0);
-
- If not fDrawToOther then
- Begin
- w:=width;
- h:=height;
- end else
- Begin
- w:=fOtherWidth;
- h:=fOtherHeight;
- end;
-
- glNewList(fGeneralLists+dl2DWindow,GL_Compile);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix;
- glLoadIdentity;
- gluOrtho2D(-w/2,w/2,-h/2,h/2);
- glMatrixMode(GL_MODELVIEW);
- // do the render stuff
- glPushMatrix();
- glLoadIdentity;
- glTranslatef(-w/2,-h/2,1);
- glEndList;
-
- glNewList(fGeneralLists+dlFocusedBorder,GL_Compile);
- saveState(stDrawing);
- {glCallList(fGeneralLists+dl2DWindow);}
- glColor4fv(@glBlack);
- glDisable(GL_BLEND);
- glDisable(GL_LINE_Stipple);
- glEnable(GL_LINE_SMOOTH);
- glDisable(GL_Depth_Test);
- glLineWidth(1.0);
- glBegin(GL_LINE_STRIP);
- glVertex2f(EdgeOff,EdgeOff);
- glVertex2f(w-EdgeOff-2,EdgeOff);
- glVertex2f(w-EdgeOff-2,h-EdgeOff-2);
- glVertex2f(EdgeOff,h-EdgeOff-2);
- glVertex2f(EdgeOff,EdgeOff);
- glEnd;
- glPopMatrix();
- //tidy up
- glMatrixMode(GL_PROJECTION);
- glPopMatrix;
- glMatrixMode(GL_MODELVIEW);
- RestoreState;
- glEndList;
- (*
- glNewList(fGeneralLists+dlUnFocusedBorder,GL_Compile);
- {glCallList(fGeneralLists+dl2DWindow);}
- saveState(stDrawing);
- glDisable(GL_BLEND);
- glDisable(GL_LINE_Stipple);
- glEnable(GL_LINE_SMOOTH);
- glDisable(GL_Depth_Test);
- glLineWidth(1.0);
- glColor4fv(@glDkGray);
-
- glBegin(GL_LINE_STRIP);
- glVertex2f(0,0);
- glVertex2f(w-0,0);
- glVertex2f(w-0,h-0);
- glVertex2f(0,h-0);
- glVertex2f(0,0);
- glEnd;
- glLineWidth(1.0);
- glPopMatrix();
- //tidy up
- glMatrixMode(GL_PROJECTION);
- glPopMatrix;
- glMatrixMode(GL_MODELVIEW);
- RestoreState;
- glEndList;
- *)
- glNewList(fGeneralLists+dlBackground,GL_COMPILE);
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_POINT_SMOOTH);
- glDisable(GL_LINE_Stipple);
- glDisable(GL_DePTH_TEST);
- glShadeModel(GL_Flat);
- glEndList;
-
- glNewList(fGeneralLists+dlForeGround,GL_COMPILE);
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_POINT_SMOOTH);
- glDisable(GL_LINE_Stipple);
- glDisable(GL_DePTH_TEST);
- glShadeModel(GL_Flat);
- glEndList;
- // check for GLErrors
- GetError;
-
- end;
- (**************************************************************)
- Procedure TCustomOpenGLWindow.BuildDisplayLists;
- Const
- pi180:double=pi/180;
- var
- Quad :GLUquadricObj;
- i :LongInt;
- x,y,z:glDouble;
- Begin
- if fGeneralLists=0 then exit;
- If assigned(fShareGL) or not fStdDisplayList then exit;
-
- If not EnableGL then exit;
- glListBase(0);
-
- glNewList(fGeneralLists+dlFullRenderMode,GL_COMPILE);
- glEnable(GL_LINE_SMOOTH);
- glEnable(GL_POINT_SMOOTH);
- glEnable(GL_LINE_Stipple);
- glEnable(GL_DePTH_TEST);
- glShadeModel(GL_Smooth);
- glEndList;
-
- glNewList(fGeneralLists+dlQuickRenderMode,GL_COMPILE);
- glEnable(GL_DePTH_TEST);
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_POINT_SMOOTH);
- glShadeModel(GL_Flat);
- glEndList;
-
-
- glNewList(fGeneralLists+dlFullAxis,GL_COMPILE);
- DrawAxes(1,0.2,0.5,AxisRes,true);
- glEndList;
-
- glNewList(fGeneralLists+dlQuickAxis,GL_COMPILE);
- DrawAxes(1,0.2,0.5,AxisRes,False);
- glEndList;
-
- BuildGrids;
-
- UpdateScreenDisplayLists;
-
- glNewList(fGeneralLists+dlPointCross,GL_COMPILE);
- saveState(stDrawing);
- glColor4fv(@glBlack);
- glBegin(gl_Lines);
- glvertex3f(-0.5,0,0);
- glvertex3f(0.5,0,0);
- glvertex3f(0,-0.5,0);
- glvertex3f(0,0.5,0);
- glvertex3f(0,0,-0.5);
- glvertex3f(0,0,0.5);
- glEnd;
- RestoreState;
- glEndList;
-
- glNewList(fGeneralLists+dlPointX,GL_COMPILE);
- saveState(stDrawing);
- glColor4fv(@glBlack);
- glBegin(gl_Lines);
- glvertex3f(-0.5,-0.5,-0.5);
- glvertex3f(0.5,0.5,0.5);
- glvertex3f(-0.5,0.5,-0.5);
- glvertex3f(0.5,-0.5,0.5);
- glvertex3f(-0.5,-0.5,0.5);
- glvertex3f(0.5,0.5,-0.5);
- glvertex3f(0.5,-0.5,-0.5);
- glvertex3f(-0.5,0.5,0.5);
- glEnd;
- RestoreState;
- glEndList;
-
- glNewList(fGeneralLists+dlPointsphere,GL_COMPILE);
- saveState(stDrawing);
- Quad:=gluNewQuadric;
- glColor4fv(@glRed); {X Axis}
- gluSphere(Quad,0.5,10,10);
- gluDeleteQuadric(Quad);
- RestoreState;
- glEndList;
-
- glNewList(fGeneralLists+dlSimpleCube,GL_COMPILE);
- saveState(stDrawing);
- glBegin(gl_QUADS);
- //top
- glVertex3d(-0.5,-0.5, 0.5);
- glVertex3d(-0.5, 0.5, 0.5);
- glVertex3d( 0.5, 0.5, 0.5);
- glVertex3d( 0.5,-0.5, 0.5);
- //Right
- glVertex3d( 0.5,-0.5,-0.5);
- glVertex3d( 0.5,-0.5, 0.5);
- glVertex3d( 0.5, 0.5, 0.5);
- glVertex3d( 0.5, 0.5,-0.5);
- //Front
- glVertex3d(-0.5, 0.5,-0.5);
- glVertex3d(-0.5, 0.5, 0.5);
- glVertex3d( 0.5, 0.5, 0.5);
- glVertex3d( 0.5, 0.5,-0.5);
- //bottom
- glVertex3d( 0.5,-0.5, -0.5);
- glVertex3d( 0.5, 0.5, -0.5);
- glVertex3d(-0.5, 0.5, -0.5);
- glVertex3d(-0.5,-0.5, -0.5);
- //left
- glVertex3d(-0.5, 0.5,-0.5);
- glVertex3d(-0.5, 0.5, 0.5);
- glVertex3d(-0.5,-0.5, 0.5);
- glVertex3d(-0.5,-0.5,-0.5);
- //back
- glVertex3d( 0.5,-0.5,-0.5);
- glVertex3d( 0.5,-0.5, 0.5);
- glVertex3d(-0.5,-0.5, 0.5);
- glVertex3d(-0.5,-0.5,-0.5);
- glEnd;
- RestoreState;
- glEndList;
-
- glNewList(fGeneralLists+dlSelectCube,GL_COMPILE);
- glColor4fv(@glBlack);
- CallList(fGeneralLists+dlSimpleCube);
- glEndList;
-
- glNewList(fGeneralLists+dlLockedSelectCube,GL_COMPILE);
- glColor4fv(@glGray50);
- CallList(fGeneralLists+dlSimpleCube);
- saveState(stDrawing);
- glColor4fv(@glBlack);
- glLineWidth(2);
- glBegin(GL_LINES);
- //top
- glVertex3d(-0.5,-0.5, 0.5);
- glVertex3d(-0.5, 0.5, 0.5);
- glVertex3d( 0.5, 0.5, 0.5);
- glVertex3d( 0.5,-0.5, 0.5);
- //Right
- glVertex3d( 0.5,-0.5,-0.5);
- glVertex3d( 0.5,-0.5, 0.5);
- glVertex3d( 0.5, 0.5, 0.5);
- glVertex3d( 0.5, 0.5,-0.5);
- //Front
- glVertex3d(-0.5, 0.5,-0.5);
- glVertex3d(-0.5, 0.5, 0.5);
- glVertex3d( 0.5, 0.5, 0.5);
- glVertex3d( 0.5, 0.5,-0.5);
- //bottom
- glVertex3d( 0.5,-0.5, -0.5);
- glVertex3d( 0.5, 0.5, -0.5);
- glVertex3d(-0.5, 0.5, -0.5);
- glVertex3d(-0.5,-0.5, -0.5);
- //left
- glVertex3d(-0.5, 0.5,-0.5);
- glVertex3d(-0.5, 0.5, 0.5);
- glVertex3d(-0.5,-0.5, 0.5);
- glVertex3d(-0.5,-0.5,-0.5);
- //back
- glVertex3d( 0.5,-0.5,-0.5);
- glVertex3d( 0.5,-0.5, 0.5);
- glVertex3d(-0.5,-0.5, 0.5);
- glVertex3d(-0.5,-0.5,-0.5);
- //sides
- glVertex3d( 0.5,-0.5,-0.5);
- glVertex3d( -0.5,-0.5,-0.5);
- glVertex3d( 0.5,-0.5, 0.5);
- glVertex3d( -0.5,-0.5, 0.5);
- glVertex3d( 0.5, 0.5, 0.5);
- glVertex3d( -0.5, 0.5, 0.5);
- glVertex3d( 0.5, 0.5,-0.5);
- glVertex3d( -0.5, 0.5,-0.5);
- glend;
- RestoreState;
- glEndList;
-
- glNewList(fGeneralLists+dlSimpleDiamond,GL_COMPILE);
- saveState(stDrawing);
- (* glBegin(gl_QUADS);
- //top
- glVertex3d(-0.5,0, 0.5);
- glend;*)
- RestoreState;
- glEndList;
-
- glNewList(fGeneralLists+dlXYCircle,GL_COMPILE);
- saveState(stDrawing);
- z:=0;
- glBegin(GL_LINE_STRIP);
- For i:=0 to 360 do
- Begin
- x:=sin(i*pi180);
- y:=Cos(i*pi180);
- glVertex3f(x,y,z);
- end;
- glend;
- RestoreState;
- glEndList;
-
- glNewList(fGeneralLists+dlXZCircle,GL_COMPILE);
- saveState(stDrawing);
- y:=0;
- glBegin(GL_LINE_STRIP);
- For i:=0 to 360 do
- Begin
- x:=sin(i*pi180);
- z:=Cos(i*pi180);
- glVertex3f(x,y,z);
- end;
- glend;
- RestoreState;
- glEndList;
-
- glNewList(fGeneralLists+dlYZCircle,GL_COMPILE);
- saveState(stDrawing);
- x:=0;
- glBegin(GL_LINE_STRIP);
- For i:=0 to 360 do
- Begin
- z:=sin(i*pi180);
- y:=Cos(i*pi180);
- glVertex3f(x,y,z);
- end;
- glEnd;
- RestoreState;
- glEndList;
-
- BuildBitMapText('Arial',10);
- BuildOutLineFont('Arial');
-
- If Assigned(fOnBuildDisplayLists) then
- fOnBuildDisplayLists(Self,fRenderMode,glCanvas);
- // check for GLErrors
- GetError;
-
- end;
- (*************************************************************)
- Procedure TCustomOpenGLWindow.BuildBitMapText(afontname:String;aSize:smallint);
- Var aLF :TLogFont;
- afont,oldfont:HFont;
- Begin
- If fRenderDC<>0 then FillChar(aLF,SizeOf(aLF),0);
- With aLF do
- Begin
- lfHeight:=-abs(aSize);
- lfOrientation:=lfEscapement;
- lfWeight:=FW_Normal;
- lfItalic:=0;
- lfUnderline:=0;
- lfStrikeOut:=0;
- lfCharSet:=ANSI_CHARSET;
- lfOutPrecision:=Out_TT_Precis;
- lfClipPrecision:=Clip_Default_Precis;
- lfQuality:=Default_Quality;
- lfPitchAndfamily:=DEFault_Pitch;
- If (length(aFontname)>0) and (Length(aFontname)<31) then
- strpcopy(@lfFacename,aFontname)
- else
- //default text
- lfFacename:='Arial';
- end;
- aFont:=CreateFontIndirect(aLF);
- If aFont<>0 then
- Begin
- OldFont:=SelectObject(fRenderDC,aFont);
- wglUseFontBitmaps(fRenderDC,0,255,fDefaultFlatTextID);
- SelectObject(fRenderDC,OldFont);
- DeleteObject(aFont);
- end;
- end;
- (******* ******************************************************)
- Procedure TCustomOpenGLWindow.BuildOutLineFont(afontname:String);
- Var aLF:TLogFont;
- afont,oldfont:HFont;
- Begin
- If fRenderDC<>0 then
- FillChar(aLF,SizeOf(aLF),0);
- With aLF do
- Begin
- lfHeight:=-12;
- lfOrientation:=lfEscapement;
- lfWeight:=FW_Normal;
- lfItalic:=0;
- lfUnderline:=0;
- lfStrikeOut:=0;
- lfCharSet:=ANSI_CHARSET;
- lfOutPrecision:=Out_TT_Precis;
- lfClipPrecision:=Clip_Default_Precis;
- lfQuality:=Default_Quality;
- lfPitchAndfamily:=DEFault_Pitch;
- If (length(aFontname)>0) and (Length(aFontname)<31) then
- strpcopy(@lfFacename,aFontname)
- else
- lfFacename:='Arial';
- end;
- aFont:=CreateFontIndirect(aLF);
- If aFont<>0 then
- Begin
- OldFont:=SelectObject(fRenderDC,aFont);
- wglUseFontOutLines(fRenderDC,0,255,fDefaultTextID,0.01,0.1,WGL_FONT_POLYGONS,@fGMF);
- SelectObject(fRenderDC,OldFont);
- DeleteObject(aFont);
- end;
- end;
- (******* ******************************************************)
- Procedure TCustomOpenGLWindow.BuildGrids;
- //set up the basic grid components
- var aPt1,apt2:tGLPoint;
- Begin
- aPt1.X:=fhome.X-fViewer.XRadius;
- aPt1.Y:=fhome.Y-fViewer.YRadius;
- aPt1.Z:=fHome.Z-fViewer.ZRadius;
- aPt2.X:=fHome.X+fViewer.XRadius;
- aPt2.Y:=fHome.Y+fViewer.YRadius;
- aPt2.Z:=fHome.Z+fViewer.ZRadius;
-
- saveState(stDrawing);
- Try
- Try
- //glcallList(fGeneralLists+dlQuickRenderMode);
- glNewList(fGeneralLists+dlGridFront,GL_Compile);
- CreateGrid(aPt1,aPt2,gtFront,0);
- glEndList;
- glNewList(fGeneralLists+dlGridBack,GL_Compile);
- CreateGrid(aPt1,aPt2,gtBack,0);
- glEndList;
- glNewList(fGeneralLists+dlGridLeft,GL_Compile);
- CreateGrid(aPt1,aPt2,gtLeftSide,0);
- glEndList;
- glNewList(fGeneralLists+dlGridRight,GL_Compile);
- CreateGrid(aPt1,aPt2,gtRightSide,0);
- glEndList;
- glNewList(fGeneralLists+dlGridTop,GL_Compile);
- CreateGrid(aPt1,aPt2,gttop,0);
- glEndList;
- glNewList(fGeneralLists+dlGridBottom,GL_Compile);
- CreateGrid(aPt1,aPt2,gtBottom,0);
- glEndList;
- //glcallList(fGeneralLists+dlFullRenderMode);
- Finally
- RestoreState;
- end;
- Except
- On EInvalidOp do else Raise;
- end;
- end;
- (******* ******************************************************)
- Procedure TCustomOpenGLWindow.CloseDisplayLists;
- Begin
- glDeleteLists(fGeneralLists,glGeneralListSize);
- glDeleteLists(fDefaultFlatTextID,256);
- glDeleteLists(fDefaultTextID,256);
- end;
- (******************************************************)
- Procedure SetAngleVal(MaxVal:Single;var CVal:Single);
- Begin
- If CVal>=MaxVal then CVal:=CVal-MaxVal else
- If CVal<=-MaxVal then CVal:=maxVal+CVal;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.ClearSelectList;
- Begin
- fSelectPoints.Clear;
- fSelectstate:=stNone;
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.ClearMoveList;
- Begin
- fMovePoints.Clear;
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.GetMeasurementData(var aMeasRec:tMeasureRecord);
- Begin
- GetListData(aMeasRec,fMovePoints);
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SnapToPoint(aX,aY,aZ:Double;aHint:String);
- // Move the cursor to this point and set the screenZ to the correct value
- Var AP:TLinkPoint;
- TP:TPoint;
- Begin
- EnableGL;
- AP:=tLinkPoint.CreateSpecial(aX,aY,aZ);
- ConvertWorldToScreen(ap);
- fViewer.ScreenZ:= aP.ScreenZ;
- TP:=ClientOrigin;
- SetCursorPos(TP.X+aP.SX,TP.Y+GetWindowPos(aP.SY));
- aP.Free;
- fSnapPoint.X:=aX;
- fSnapPoint.Y:=aY;
- fSnapPoint.Z:=aZ;
- fSnapOn:=True;
- UpdateScreenCoordsLabel;
- UpdateExtraScreenCoordsLabel;
- // check for GLErrors
- GetError;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.ShowGLHint(Var aHintStr:String; Var CanShow:Boolean; Var HintInfo:tHintInfo);
- // call to handle any hint showing stuff
- Begin
- If (HintInfo.HintControl is TCustomOpenGLWindow) then
- With HintInfo do Begin
- ReShowTimeOut:=50;
- HideTimeOut :=50;
- end;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.getBirdsEyeView(aBP:tBitMap;aSize:LongInt);
- //return bitmap filled with bitmap centred on mouse pos and size
- Begin
- end;
- (******************************************************)
- Function TCustomOpenGLWindow.GetSizedBitMapImage(aBP:tBitMap):Boolean;
- //return a high resolution bitmap of current view
- var oldDC:HDC;
- oldRC:HGLRC;
- oldcanvas:tCanvas;
- TempGL:TAbstractOpenGLBitmap;
- oldGDI:Boolean;
- Begin
- Result:=False;
- iF Not Assigned(aBP) then exit;
- If (aBP.Width=0) or (aBP.Height=0) then exit;
-
- TEMPGL:= TAbstractOpenGLBitmap.CreateInit(aBP,fBackColor);
- If TempGl.GLSessionOK then
- Begin
- oldDC:=fRenderDC;
- fREnderDC:=TEMPGL.RenderDC;
- OldRC:=fHRC;
- fHRC:=TEMPGL.GLRC;
- oldCanvas:=fCanvas;
- fCanvas:=TEMPGL.GLCanvas;
- OldGDI:=fGDIGeneric;
- fGDIGeneric:=True;
-
- fOtherWidth:=aBP.Width;
- fOtherHeight :=aBP.Height; // bitmap size=0 when drawing to screen
- fDrawToOther:=True;
-
- SetUpViewPort;
- SetUpViewingFrustrum;
- SetUpViewingTransform;
- BuildDisplayLists;
- UpdateScreenPos;
-
- UpdateScreenDisplayLists;
- PaintWindow(fRenderDC);
-
- getBitMapImage(aBP);
- //tidy up
- fDrawToOther:=False;
- fOtherWidth:=0;
- fOtherHeight :=0; // bitmap size=0 when drawing to screen
-
- fRenderDC :=oldDC;
- fHRC :=oldRC;
- fCanvas :=oldcanvas;
- fGDIGeneric:=OldGDI;
- TempGL.Free;
-
- SetUpViewPort;
- SetUpViewingFrustrum;
- SetUpViewingTransform;
-
- UpdateScreenPos;
- UpdateScreenDisplayLists;
- RePaint;
- Result:=True;
- end else
- MessageDlg('Unable to build a memory image.',mtInformation,[mbok],0);
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.getFittedBitMapImage(aBP:tBitMap);
- //return a specially composed bitmap filled with current view
- var tempBM:tBitMap;
- aRect:TRect;
- Info: PBitmapInfo;
- InfoSize: DWord;
- Image: Pointer;
- ImageSize: DWord;
-
- begin
- If not assigned(aBP) then exit;
- If not enableGL then exit;
- Screen.Cursor:=crHourglass;
- // creates a fitted bitmap
- TempBM:=tBitmap.Create;
- getBitMapImage(tempBM);
- // stretch to fit the supplied bitmap
- With aRect do
- Begin
- Left:=0;Top:=0;
- Right:=aBP.Width;Bottom:=aBP.Height;
- end;
-
- with tempBM do
- begin
- GetDIBSizes(Handle,InfoSize,ImageSize);
- Getmem(Info,InfoSize);
- try
- GetMem(Image,ImageSize);
- try
- GetDIB(Handle,Palette,Info^,Image^);
- with Info^.bmiHeader do
- StretchDIBits(aBP.Canvas.handle,aRect.left,arect.top,aRect.right-arect.left,
- aRect.bottom-aRect.top,0,0,biWidth,biHeight,image,Info^,DIB_RGB_COLORS,
- SRCCOPY);
- finally
- FreeMem(Image,ImageSize);
- end;
- finally
- FreeMem(info,InfoSize);
- end;
- end;
- TempBM.Free;
- // check for GLErrors
- GetError;
- Screen.Cursor:=crDefault;
- {end;}
- end;
- (******************************************************)
- Function TCustomOpenGLWindow.getScaledMetaFileImage(PixSizeX,PixSizeY:Integer; //Pixel size of window
- PixResX,PixResY:Single ; //scale in Pixel/mm
- aPrintScale:Double):tMetaFile;//scale value -1=not to scale
- //draw the image to a Metafile. Will fail if in perspective view.
- Type
- TempRec =Record
- X,Y :Integer;
- end;
- Var h,w:GLfloat;
- Dist:Double;
- aMF:tMetaFile;
- MaxVal:TempRec;
- PixScaleX,PixScaleY,TempScale:Double;
- TempX,TempY: Integer;
-
- Begin
- Result:=nil;
- If (PixSizeX=0) or (PixSizeY=0) then exit;
- If (PixResX=0) or (PixResY=0) then exit;
- If Perspective and (aPrintScale>0) then exit;
- //cant do scale in perspective view
-
- aMF:=tMetaFile.Create;
-
- If aPrintscale<=0 then
- TempScale:=1000 else
- TempScale:=aPrintScale;;
- Try
- EnableGL;
- aMF.Width :=PixSizeX;
- aMF.Height:=PixSizeY;
-
- PixScaleX:=1;
- PixScaleY:=1;
- TempX:=PixSizeX;
- TempY:=PixSizeY;
-
- glGetIntegerv(GL_MAX_VIEWPORT_DIMS,@MaxVal);
- // If the requested size is larger tahn the GL session can support
- // then the size must re rescaled to suit.
- If (PixSizeX>MaxVal.X) or (PixSizeY>MaxVal.Y) then
- Begin
- //set up the pixscale values and the best viewport size.
- If PixSizeX=PixSizeY then
- Begin
- // same siz in X and Y
- PixScaleY:=(maxVal.X/PixSizeX)*(PixResX/PixResY);
- PixScaleX:=(MaxVal.Y/PixSizeY)*(PixResY/PixResX);
- TempX:=Round(PixSizeX*PixScaleX);
- TempY:=Round(PixSizeY*PixScaleY);
- end else
- If PixSizeX>PixSizeY then
- Begin
- PixScaleY:=(maxVal.X/PixSizeX)*(PixResX/PixResY);
- TempX:=PixSizeX;
- TempY:=Round(PixSizeY*PixScaleY);
- end else
- Begin
- PixScaleY:=(MaxVal.Y/PixSizeY)*(PixResY/PixResX);
- TempY:=PixSizeY;
- TempX:=Round(PixSizeX*PixScaleY);
- end;
- end;
-
- // viewport matrix setup with the new "window" size
- glViewport(0,0,TempX,TempY);
- glGetIntegerv(GL_VIEWPORT,pGLInt(@fViewPort));
-
- // setup the Projection for the scale case else leave alone
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity;
- // this may need some work
- h:=(PixSizeX/PixResX) *(TempScale/1000);
- w:=(PixSizeY/PixResY) *(TempScale/1000);
-
- with fViewer do
- begin
- Dist:=Distance*5;
- //manage the perspective case or the Ortho case
- glOrtho(-w/2,w/2,-h/2,h/2,1,Dist);
- fGLperPixel:=w/tempX;
- //check this value
- glGetDoublev(GL_PROJECTION_MATRIX,pGLDouble(@fprojMatrix));
- // projection matrix
- glMatrixMode(GL_MODELVIEW);
- end; //end setup modelview
- // check for GLErrors
- GetError;
- // need to sset up the temporaru draw to Other flag
-
- fDrawToOther:=True;
- fOtherWidth :=TempX;
- fOtherHeight:=TempY;
-
- If GetMetaFileImage(aMF,1,1/PixScaleX,1/PixScaleY) then
- Result :=aMF else
- aMF.Free;
-
- Finally
- //reset the GL session;
- fDrawToOther:=False;
- fOtherWidth:=0;
- fOtherHeight:=0;
- SetUpViewPort;
- SetUpViewingFrustrum;
- SetUpViewingTransform;
- end;
- end;
- (******************************************************)
- Function TCustomOpenGLWindow.getMetaFileImage(aMF:tMetaFile;UseMFHeight:Integer;XScale,YScale:Double):Boolean;
- //O= use window height 1=use mf.height 2= use mf.mmheight
- var
- TempMFC : tMetaFileCanvas;
- Buffer : Pointer;
- fFeedBackData ,Step : Integer;
- GotAllTheData : Boolean;
- BufSize:Longint;
- tHt : Integer;
- oldCanvas:TCanvas;
- Begin
- Result:=False;
- If not assigned(aMF) then exit;
- Case UseMFHeight of
- 0:tHt:=Height;
- 1:tHt:=aMF.Height;
- 2:tHt:=aMF.mmHeight;
- else tHt:=Height;
- end;
- TempMFC:=TMetaFileCanvas.CreateWithComment(aMF,0,'OpenGL App','GL Scene');
- //create a metafile canvas
- GotAllTheData:=False;
- Step:=1;
- oldCanvas:=fCanvas;
- fCanvas:=TempMFC;
- // swap in a temporary canvas
- GetViewPortGrid(glGridType(fViewmode),20);
- // setup the grid data
-
- BufSize:=fbBufferSizetiny;
- Repeat
- If Step>1 then BufSize:=BufSize*2;
- GetMem(Buffer,BufSize*SizeOf(Single));
- glFeedbackBuffer(BufSize,GL_3D_COLOR,Buffer);
- // set the render to the feedback buffer
- glRenderMode(GL_FEEDBACK);
- fRebuildNeeded:=True;
- // render the window
- GLRenderWindow(False);
- fFeedBackData:=glRenderMode(GL_RENDER);
- If (fFeedBackData>=0) then
- Begin
- GotAllTheData:=True;
- DrawFeedBackDataToCanvas(TempMFC,
- fFeedbackdata,
- pFeedBackArray(Buffer),
- GL_3D_COLOR,
- tHt,
- nil,
- XScale,YScale);
- end;
- FreeMem(Buffer,BufSize*SizeOf(Single));
- Inc(step);
- until GotAllTheData or (Step=4);
- Result:=GotAllTheData;
- TempMFC.Free;
- fCanvas:=oldCanvas;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.CopyToClipBoard;
- //copy the current view to the clipboard as a bitmap and a metafile
- const
- HiMetricPerInch : Longint = 2540;
-
- var tempBM : tBitMap;
- TempMF : tMetaFile;
-
- aFormat : word;
- aData : tHandle;
- aPalette : hPalette;
- Begin
- TempBM:=tBitmap.Create;
- TempMF:=TMetaFile.Create;
- TempMF.Width:=Width;
- TempMF.Height:=Height;
-
- Try
- getBitMapImage(tempBM);
- tempbm.SaveToClipboardFormat(aFormat,aData,apalette);
- With ClipBoard do
- Begin
- Open;
- SetAsHandle(aFormat,AData);
- if aPalette <> 0 then SetClipboardData(CF_PALETTE, aPalette);
- end;
-
- getMetaFileImage(TempMF,0,1,1);
- TempMF.SaveToClipboardFormat(aFormat,aData,apalette);
- With ClipBoard do
- Begin
- SetAsHandle(aFormat,AData);
- if aPalette <> 0 then SetClipboardData(CF_PALETTE, aPalette);
- end;
- finally
- ClipBoard.Close;
- tempBM.Free;
- TempMF.Free;
- end;
- end;
-
- (******************************************************)
- Procedure TCustomOpenGLWindow.getBitMapImage(aBP:tBitMap);
- var
- BitsMem : pointer;
- BmInfo : tBitmapInfo;
- bitsize,
- WinWidth,
- WinHeight,
- scanWidth,
- T1,T2 : DWord;
- aRGB : pGLRGB;
- temp : GLUByte;
- tDC : HDC;
- TempBitMap : HBitMap;
- aMem : TMemoryStream;
- Info : TBitmapFileHeader;
- InfoSize : DWord;
- InfoHeader : TBitMapInfoHeader;
-
- Procedure SwapTheRGBValues;
- Var iVal,jVal:DWord;
- Begin
- //swap the bytes as the RGB values are in the reverse order
- T1:=LongInt( Bitsmem);
- For ival:=0 to WinHeight-1 do
- Begin
- T2:=T1+(ival*ScanWidth);
- aRGB:=pGLRGB(ptr(T2));
- For jval:=0 to WinWidth-1 do
- Begin
- If aRGB^[1]<>aRGB^[3] then //only swap if the values are different
- Begin
- Temp:=aRGB^[1];
- aRGB^[1]:=aRGB^[3];
- aRGB^[3]:=Temp;
- end;
- t2:=t2+3; // move to the next set
- aRGB:=pGLRGB(ptr(T2));
- end;
- end;
- end;
-
- Begin
- //quit if not valid to build
- If not assigned(aBP) then exit;
- If (fRenderDC=0) or (fHRC=0) then exit;
- // ensure the GL session is enabled
- If not enableGL then exit;
- //set up the BMF info and data structures
- FillChar(BmInfo,SizeOf(BmInfo),0);
-
- WinWidth:= fviewport[3];//width of current GL screen
- WinHeight:= fviewport[4];//height of the current GL screen
- ScanWidth:=(WinWidth)*3; // scan width for the bitmap
- //need to fix alignment to 4 byte
- ScanWidth:=(ScanWidth+3) and $FFFFFFFC;
- BitSize:=ScanWidth*(WinHeight); //calculate the memory size needed for the bitmap
-
- // flush the GDI pipeline
- glFinish;
- // set up the gl read
- If not fDrawToOther then
- glReadBuffer(GL_Back) else
- glReadBuffer(GL_Front);
- glPixelStorei(GL_PACK_ALIGNMENT,4);
- glPixelStorei(GL_PACK_ROW_LENGTH,0);
- glPixelStorei(GL_PACK_SKIP_ROWS,0);
- glPixelStorei(GL_PACK_SKIP_PIXELS,0);
- Try
- // read the glpixels from the video buffer
- GetMem(Bitsmem,bitsize); // Allocate memory to read pixels into
- Except
- on EOutOfMemory do Bitsmem:=nil
- else Raise;
- end;
- If BitsMem<>Nil then
- Begin
- // get th bits data
- glReadPixels(0, //X
- 0, //Y
- WinWidth, //Width
- WinHeight, //Height
- GL_RGB, //Format of data read
- GL_UNSIGNED_BYTE, //Type of data
- Bitsmem); // pointer to memory storage
- SwapTheRGBValues;
- // reverse the order of the RGB values
- TDC:=CreateDC('Display',nil,nil,nil);
- // attempt to create a DIB bitmap handle
- If TDC<>0 then
- Begin
- With BmInfo.bmiheader do
- Begin
- biSize:=SizeOf(TBitMapInfoHeader);
- biWidth:=WinWidth; //width of the bitmap
- biHeight:=WinHeight; //height of the bitmap
- biPlanes:=1; //always 1
- biBitCount:=24; //24 bit colour for bitmap
- biCompression:=BI_RGB; //No compression
- biSizeImage:=BitSize; //size of the image
- biXPelsPermeter:=2952; //75dpi
- biYPelsPermeter:=2952; //75dpi
- biClrUsed:=0;
- biClrImportant:=0;
- end;
- //set up the Bitmap info header
- TempBitMap:= CreateDIBitmap(tDC,BmInfo.bmiheader,
- cbm_Init,Bitsmem,bmInfo,DIB_RGB_COLORS)
- end else TempBitMap:=0;
- try
- If tempBitMap<>0 then
- Begin
- SelectObject(TDC,TempBitMap); //select the bitmap into the DC
- aBP.Handle:=TempBitMap; //assign the bitmap to the tBitmap handle
- end else
- //fail on the BID create handle then manually build the bitmap
- Begin
- FillChar(Info,SizeOf(Info),0);
- FillChar(InfoHeader,SizeOf(InfoHeader),0);
- With Info do
- Begin
- bfType:=$4D42;
- InFoSize:=SizeOf(InfoHeader);
- bfSize:=sizeOf(info)+ InfoSize+ bitsize;
- bfOffBits:=sizeOf(info)+ Infosize;
- end;
- With InfoHeader do
- Begin
- biSize:=SizeOf(InfoHeader);
- biWidth:=WinWidth;
- biHeight:=WinHeight;
- biPlanes:=1;
- biBitCount:=24;
- biCompression:=BI_RGB;
- biSizeImage:=BitSize;
- biXPelsPermeter:=2952;//75dpi
- biYPelsPermeter:=2952;//75dpi
- biClrUsed:=0;
- biClrImportant:=0;
- end;
- aMem:=tMemoryStream.Create;// create a temporary memory stream
- aMem.Write(Info,SizeOf(info)); // write the info block
- aMem.Write(InfoHeader,SizeOf(InfoHeader));//write the information header block
- aMem.Write(BitsMem^,BitSize); //write the pixels data
- aMem.Position:=0; //reset the stream
- aBP.LoadFromStream(aMem); // load theimage into the tBitMap
- aMem.Free; //tidy up
- end;
- Finally
- //tidy up
- If TDC<>0 then DeleteDC(TDC);
- FreeMem(Bitsmem,bitsize);
- end;
- end;
- // check for GLErrors
- GetError;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetXCubeSize(aVal:Double);
- Begin
- If (fViewer.XRadius=aVal)then exit;
- fViewer.XRadius:=aVal;
- if fHRC=0 then exit;
- ReSetView(false);
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetYCubeSize(aVal:Double);
- Begin
- If (fViewer.YRadius=aVal)then exit;
- fViewer.YRadius:=aVal;
- if fHRC=0 then exit;
- ReSetView(false);
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetZCubeSize(aVal:Double);
- Begin
- If (fViewer.ZRadius=aVal)then exit;
- fViewer.ZRadius:=aVal;
- if fHRC=0 then exit;
- ReSetView(false);
- Repaint;
- end;
- (******************************************************)
- function TCustomOpenGLWindow.GetPerspective: Boolean;
- Begin
- Result:= fViewer.Perspective;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetPerspective(AState:Boolean);
- Var TempZ:Double;
- aScrnPt:TPoint;
-
- Begin
- If fViewer.Perspective=aState then exit;
- fViewer.Perspective:=AState;
- if fHRC=0 then exit;
- SetUpViewPort;
- SetUpViewingFrustrum;
- SetUpViewingTransform;
- //Set screenZ value by projecting fHome onto the screen
- If not ProjectOnScreen(fHome,aScrnPt,TempZ) then
- TempZ:=0.5;
- viewer.screenZ:=TempZ;
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetSimpleAxis(AState:Boolean);
- Begin
- If fSimpleAxis=aState then exit;
- fSimpleAxis:=AState;
- if fHRC=0 then exit;
- SetUpViewingFrustrum;
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetRenderMode(aRM:GLRenderState);
- Begin
- If aRM=fRenderMode then exit;
- fRenderMode:=aRM;
- if fHRC=0 then exit;
- //GLRenderState =(rmFull,rmQuick,rmMotion,rmThread,rmAnimation,rmViewAnimate,fmGDIOnly);
- Case fRenderMode of
- rmFull: CallList(fGeneralLists+dlFullRenderMode) ;
- rmQuick: CallList(fGeneralLists+dlQuickRenderMode) ;
- else CallList(fGeneralLists+dlFullRenderMode);
- end;
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetBackColor(aColor:GLBackground);
- Begin
- fBackColor:=aColor;
- Case fBackColor of
- glWhiteBkgd:
- Begin
- glBlack[1]:=0;
- glBlack[2]:=0;
- glBlack[3]:=0;
- glBlack[4]:=1;
- end;
- glBlackBkgd:
- Begin
- glBlack[1]:=1;
- glBlack[2]:=1;
- glBlack[3]:=1;
- glBlack[4]:=1;
- end;
- end;
- If fHRC=0 then exit;
- GLLock;
- EnableGL;
- If fBackColor=glWhiteBkgd then
- glClearColor(1.0,1.0,1.0,1.0)
- else
- glClearColor(0.0,0.0,0.0,1.0);
- BuildDisplayLists;
- Repaint;
- // check for GLErrors
- GetError;
-
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetToolMode(aMode:GLToolMode);
- Begin
- If (aMode=ftoolmode)or(fMoveMode<>mmNone) then exit;
- fToolMode:=aMode;
- fSelectstate:=stNone;
- {If fToolMode:=tlNone then }ClearSelectList;
- If fHRC=0 then exit;
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetRefPoint(val:tGLPoint);
- // Set up the home point
- Begin
- If (fHome.X=Val.X) and (fHome.Y=Val.Y) and (fHome.Z=val.Z) then exit;
- fHome:=Val;
- ResetView(True);
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetMoveMode(aMode:GLMoveMode);
- Begin
- If aMode=fMoveMode then exit;// do nothing
- // handle turning off the toolmode
- If (aMode<>mmNone) then
- Begin
- fLastToolMode:=fToolMode;
- fToolMode:=tlNone;
- end
- else
- fToolMode:=fLastToolMode;
- // change the move mode
- fMoveMode:=aMode;
- If ((fMoveMode=mmZoom)or
- (fMoveMode=mmSlide))and
- Perspective then Perspective:=False;
- ClearMoveList;
- If fHRC=0 then exit;
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetViewMode(aMode:GLViewMode);
- Begin
- If aMode=fViewMode then exit;
- fViewMode:=aMode;
- If fHRC=0 then exit;
- ReSetView(False);
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetScale(aVal:Single);
- Begin
- If aVal=fViewer.Scale then exit;
- fViewer.Scale:=aval;
- If fHRC=0 then exit;
- ReSetView(False);
- Repaint;
- end;
- (******************************************************)
- Procedure TCustomOpenGLWindow.SetHUD(Val:Boolean );
- Begin
- If fHUDon=val then exit;
- fHUDon:=val;
- If fHRC=0 then exit;
- Repaint;
- end;
- (******************************************************)
- (******* ******************************************************)
- constructor TOpenGLCanvas.Create(AOwner: TComponent);
- Begin
- Inherited Create;
- fColor:=glBlack;
- fLineWidth:=1;
- f3DMode:=True;
- fPointSize:=2;
- If (aOwner is TCustomOpenGLWindow) then fGLWin:=TCustomOpenGLWindow(aOwner);
- end;
- (******* ******************************************************)
- destructor TOpenGLCanvas.Destroy;
- Begin
- Inherited Destroy;
- end;
- (******* ******************************************************)
- Procedure TOpenGLCanvas.SetLineWidth(aWidth:glFloat);
- Var MaxMinWidth:Array[1..2]of glFloat;
- Begin
- If aWidth=fLinewidth then exit;
- glGetFloatv(GL_Line_Width_Range,@MaxMinWidth);
- If (aWidth>MaxMinWidth[2]) then fLineWidth:=MaxMinWidth[2] else
- If (aWidth<MaxMinWidth[1]) then fLineWidth:=MaxMinWidth[1] else
- fLineWidth:=aWidth;
- glLineWidth(fLineWidth);
- end;
- (******* ******************************************************)
- Procedure TOpenGLCanvas.SetLineStyle(aStyle:gluShort);
- Begin
- If aStyle=fStipple then exit;
- fStipple:=aStyle;
- If fStipple<>stContinous then
- Begin
- glEnable (GL_LINE_Stipple);
- glLineStipple(1, fStipple);
- end else
- glDisable(GL_LINE_STIPPLE);
- end;
- (******* ******************************************************)
- Procedure TOpenGLCanvas.MoveTo(aPt:tGLPoint);
- Begin
- fCurrentPoint.X:=aPt.X;
- fCurrentPoint.Y:=aPt.Y;
- fCurrentPoint.Z:=aPt.Z;
- {set RastorPos for possible test drawing}
- glRasterPos3dv(@aPt);
- end;
- (******* ******************************************************)
- Procedure TOpenGLCanvas.DrawPoint(aPt:tGLPoint);
- Begin
- glColor4fv(@fColor);
- glPointSize(fPointSize);
- glPushmatrix;
- Case fPointMode of
- ptSimple:
- Begin
- glBegin(GL_Points);
- If f3DMode Then glVertex3dv(@aPt) else glVertex2dv(@aPt);
- glEnd;
- end;
- ptCross:
- Begin
- glTranslated(aPt.X,aPt.Y,aPt.Z);
- If fPointSize>0 then glScalef(fPointSize,fPointSize,fPointsize);
- fGLWin.Calllist(fGLWin.DisplayList+dlPointCross);
- end;
- ptShpere:
- Begin
- glTranslated(aPt.X,aPt.Y,aPt.Z);
- If fPointSize>0 then glScalef(fPointSize,fPointSize,fPointsize);
- fGLWin.Calllist(fGLWin.DisplayList+dlPointSphere);
- end;
- ptCube:;
- end; {case}
- glPopMatrix;
- MoveTo(aPt);
- end;
- (******* ******************************************************)
- Procedure TOpenGLCanvas.LineTo(aPt:tGLPoint);
- Begin
- glLineWidth(fLineWidth);
- //set the line width (stored by the GLCanvas)
- glColor4fv(@fColor);
- //set the line colour (stored by the GLCanvas)
- glPassThrough(1000+fLinewidth);
- //use the glPassthrough to signal a line width when creating a metafile
- glBegin(GL_Lines);
- //call the OpenGL Start line
- If f3DMode then
- Begin
- glVertex3dv(@fCurrentPoint);
- //uses the current point as the start point of the line (stored by the GLCanvas)
- glVertex3dv(@aPt);
- //pass pointers to the 3D points data
- //passing pointers to data is faster than passing the data!!!!
- end else
- Begin
- glVertex2dv(@fCurrentPoint);
- glVertex2dv(@aPt);
- // pass through pointers signalling 2D data
- end;
- glEnd;
- // close the OpenGL begin
- MoveTo(aPt);
- // set the glCanvas current point to the end point of the line
- end;
- (******* ******************************************************)
- Procedure TOpenGLCanvas.DrawLine(aStart,aEnd:tGLPoint);
- Begin
- glLineWidth(fLineWidth);
- glBegin(GL_Lines);
- glColor3fv(@fColor);
- glVertex3dv(@aStart);
- glVertex3dv(@aEnd);
- glEnd;
- MoveTo(aEnd);
- end;
- (*************************************************************)
- Procedure TOpenGLCanvas.DrawTriangle(P1,P2,P3:tGLPoint;C1,C2,C3:glColorVal);
- Begin
- glBegin(GL_TRIANGLES);
- glColor3fv(@C1);
- glVertex3dv(@P1);
- glColor3fv(@C2);
- glVertex3dv(@P2);
- glColor3fv(@C3);
- glVertex3dv(@P3);
- glEnd;
- end;
- (*************************************************************)
- Procedure TOpenGLCanvas.DrawQuad(P1,P2,P3,P4:tGLPoint;C1,C2,C3,C4:glColorVal);
- Begin
- glBegin(GL_QUADS);
- glColor3fv(@C1);
- glVertex3dv(@P1);
- glColor3fv(@C2);
- glVertex3dv(@P2);
- glColor3fv(@C3);
- glVertex3dv(@P3);
- glColor3fv(@C4);
- glVertex3dv(@P4);
- glEnd;
- end;
- (*************************************************************)
- Procedure TOpenGLCanvas.DrawRectangle(P1,P2:tGLPoint);
- Begin
- glLineWidth(fLineWidth);
- glColor4fv(@fColor);
- glRectdv(@P1,@P2);
- end;
- (*************************************************************)
- Procedure TOpenGLCanvas.TextOut2D(loc:tGLPoint;aSize:glFloat;aStr:String);
- Begin
- If length(aStr)>255 then exit;
- If not fGLWin.StdDisplayList then exit;
- glListBase(fGLWin.fDefaultFlatTextID);
- glPushMatrix;
- glScalef(aSize,aSize,aSize);
- glRasterPos3dv(@loc);
- glCallLists(length(aSTR),GL_Unsigned_Byte,@aStr[1]);
- glPopMatrix;
- glListBase(0);
- end;
- (*************************************************************)
- Procedure TOpenGLCanvas.TextOut3D(loc:tGLPoint;aSize:glFloat;aStr:String);
- Begin
- If (aSize=0) then exit;
- If not fGLWin.StdDisplayList then exit;
- If length(aStr)>255 then exit;
- glListBase(fGLWin.fDefaultTextID);
- glPushMatrix;
- glTranslatef(loc.X,loc.Y,loc.Z);
- glScalef(aSize,aSize,aSize);
- glCallLists(length(aSTR),GL_Unsigned_Byte,@aStr[1]);
- glPopMatrix;
- glListBase(0);
- end;
- (*************************************************************)
- Procedure TOpenGLCanvas.DrawAxis(loc:tGLPoint;aSize:glFloat;aMode:GLRenderState);
- Begin
- If (aSize=0) then exit;
- If not fGLWin.StdDisplayList then exit;
- glPushMatrix;
- glTranslated(loc.X,loc.Y,loc.Z);
- glScalef(aSize,aSize,aSize);
- If aMode= rmFull then
- fGLWin.CallList(fGLWin.DisplayList+dlFullAxis)
- else
- fGLWin.CallList(fGLWin.DisplayList+dlQuickAxis);
- glPopMatrix;
- end;
- (*************************************************************)
- Procedure TOpenGLCanvas.CircleXY(loc:tGLPoint;XRadius,YRadius:glFloat);
- Begin
- If (XRadius=0) or (YRadius=0) then exit;
- If not fGLWin.StdDisplayList then exit;
- glPushMatrix;
- glTranslated(loc.X,loc.Y,loc.Z);
- glScalef(XRadius,yRadius,1);
- glLineWidth(fLineWidth);
- glColor4fv(@fColor);
- fGLWin.CallList(fGLWin.DisplayList+dlXYCircle);
- glPopMatrix;
- MoveTo(loc);
- end;
-
- (*************************************************************)
- Procedure TOpenGLCanvas.CircleXZ(loc:tGLPoint;XRadius,ZRadius:glFloat);
- Begin
- If (XRadius=0) or (ZRadius=0) then exit;
- If not fGLWin.StdDisplayList then exit;
- glPushMatrix;
- glTranslated(loc.X,loc.Y,loc.Z);
- glScalef(XRadius,1,ZRadius);
- glLineWidth(fLineWidth);
- glColor4fv(@fColor);
- fGLWin.CallList(fGLWin.DisplayList+dlXZCircle);
- glPopMatrix;
- MoveTo(loc);
- end;
- (*************************************************************)
- Procedure TOpenGLCanvas.DrawSelectHandle(aSize:Double);
- // Selection handle at present position
- Begin
- glPushMatrix;
- If not fGLWin.StdDisplayList then exit;
- glTranslated(fCurrentPoint.X,fCurrentPoint.Y,fCurrentPoint.Z);
- glScalef(aSize,aSize,aSize);
- fGLWin.CallList(fGLWin.DisplayList+dlSelectCube);
- glPopMatrix;
- end;
- (*************************************************************)
- Procedure TOpenGLCanvas.DrawLockedSelectHandle(aSize:Double);
- // draw locked selection handle
- Begin
- glPushMatrix;
- If not fGLWin.StdDisplayList then exit;
- glTranslated(fCurrentPoint.X,fCurrentPoint.Y,fCurrentPoint.Z);
- glScalef(aSize,aSize,aSize);
- fGLWin.CallList(fGLWin.DisplayList+dlLockedSelectCube);
- glPopMatrix;
- end;
- (*************************************************************)
- Procedure TOpenGLCanvas.CircleYZ(loc:tGLPoint;YRadius,ZRadius:glFloat);
- Begin
- If (YRadius=0) or (ZRadius=0) then exit;
- If not fGLWin.StdDisplayList then exit;
- glPushMatrix;
- glTranslated(loc.X,loc.Y,loc.Z);
- glScalef(1,YRadius,ZRadius);
- glLineWidth(fLineWidth);
- glColor4fv(@fColor);
- fGLWin.CallList(fGLWin.DisplayList+dlYZCircle);
- glPopMatrix;
- MoveTo(loc);
- end;
- (*************************************************************)
- (*************************************************************)
- { TCustomOpenGLWindowActionLink }
-
- procedure TCustomOpenGLWindowActionLink.AssignClient(AClient: TObject);
- begin
- inherited AssignClient(AClient);
- FClient := AClient as TCustomOpenGLWindow;
- end;
-
- function TCustomOpenGLWindowActionLink.IsHelpContextLinked: Boolean;
- begin
- Result := inherited IsHelpContextLinked and
- (FClient.HelpContext = (Action as TCustomAction).HelpContext);
- end;
-
- procedure TCustomOpenGLWindowActionLink.SetHelpContext(Value: THelpContext);
- begin
- if IsHelpContextLinked then FClient.HelpContext := Value
- end;
- (******* ******************************************************)
- (******* ******************************************************)
- (*
- procedure Register;
- begin
- RegisterComponents('OpenGL', [TCustomOpenGLWindow]);
- end;
- *)
- end.
-